phpfox: how to print_r variables? - phpfox

I have that in controller:
$aUser = Phpfox::getUserBy('user_name');
How to print_r the content of $aUser (for debugging process to see the content of that object) ?
I tried print_r(aUser) in controller: NO OUTPUT
I tied {$aUser}in templates: output Array()

In controller files, you can use:
d($aUser);
In template files, you can use:
{$aUser|var_dump}

Related

Laravel Blade: Use commands from string

I have variable in Controller:
$abc = '#include('partials.formerror', array(.....))';
And I send that variable to view:
\View::share([
"abc" => $abc,
]);
And I want in view:
......
......
#include('partials.formerror', array(....)
......
......
#include('partials.formerror', array(....) is dynamic content from Controller. But it's COMMAND of Blade, not plain text. How can I do that?
You need a string blade compiler like this one:
https://packagist.org/packages/wpb/string-blade-compiler
Laravel doens't allow blade rendering from strings out of the box.
Fyi: you could also use Blade::compileString which imho is not an elegant solution
your answer is here: https://laravel.com/docs/5.2/views#view-composers
You can create a view composer and attache dynamic content to your view.

Can't see variable inside content view in Laravel 4 with Blade

I have a problem understanding how variables work inside the Laravel templating system, Blade.
I set the variables in the controller, I can see them in the first view I make, but not inside the next one.
I'm using a master.blade.php file that holds the header and footer of the page, yielding the content in the middle. I can use the variable inside the master.blade.php file, but not inside the content blade file (variable undefined).
For example, for the contact page:
CONTROLLER FUNCTION:
$this->data['page'] = "contact";
$this->layout->content = View::make('pages.contact');
$this->layout->with('data', $this->data);
MASTER.BLADE.PHP:
if ($data['page'] == 'contact')
{ //do something, it works }
#yield('content')
CONTACT.BLADE.PHP:
if ($data['page'] == 'contact')
{// do something. ErrorException Undefined variable: data}
Am I missing something or is it a known restriction?
Thanks!
The problem was that I was passing the variables only to the layout:
Instead of:
$this->layout->content = View::make('pages.contact');
$this->layout->with('data', $this->data);
I fixed it using:
$this->layout->content = View::make('pages.contact', array('data' => $this->data));
$this->layout->with('data', $this->data);
This way passing the variables to the layout, but also to that particular view.
Hope it helps someone.

how to load view into another view codeigniter 2.1?

Ive been working with CI and I saw on the website of CI you can load a view as a variable part of the data you send to the "main" view, so, according the site (that says a lot of things, and many are not like they say ...ej pagination and others) i did something like this
$data['menu'] = $this->load->view('menu');
$this->load->view ('home',data);
the result of this is that I get an echo of the menu in the top of the site (before starts my body and all) and where should be its nothing, like if were printed before everything... I have no idea honestly of this problem, did anybody had the same problem before?
Two ways of doing this:
Load it in advance (like you're doing) and pass to the other view
<?php
// the "TRUE" argument tells it to return the content, rather than display it immediately
$data['menu'] = $this->load->view('menu', NULL, TRUE);
$this->load->view ('home', $data);
Load a view "from within" a view:
<?php
// put this in the controller
$this->load->view('home');
// put this in /application/views/home.php
$this->view('menu');
echo 'Other home content';
Create a helper function
function loadView($view,$data = null){
$CI = get_instance();
return $CI->load->view($view,$data);
}
Load the helper in the controller, then use the function in your view to load another one.
<?php
...
echo loadView('secondView',$data); // $data array
...
?>

Codeigniter Views with Dynamic Parameters

I load the multiple views from the controller, in order to display a page.
$this->load->view('header');
$this->load->view('content', $data);
$this->load->view('sidebar1', $data1);
$this->load->view('sidebar2', $data2);
$this->load->view('footer');
However I think its not a clean approach. Can it be improved by creating a single main view, for example "views/page" which includes all above views in it. Then instead of calling all the above views, i can call only main view, for example:
$this->load->view('main');
In this case how can I pass the variables for the content, sidebar1 and sidebar2?
Thanks
Pass the data for each view as an array to your main view, then pass those arrays on as your main view loads the subviews.
$data['sidebar1_data'] = array($one => 'one');
$data['sidebar2_data'] = array($two => 'two');
Then in your main view:
$this->load->view('sidebar1', $sidebar1_data);
$this->load->view('sidebar2', $sidebar2_data);
Within my projects, I have a tendency to do:
$this->load->vars($data);
$this->load->view('template_name');
Where my template loads in other views within itself.
The CodeIgniter documentation states the following for the method $this->load->vars():
"This function takes an associative array as input and generates variables using the PHP extract function. This function produces the same result as using the second parameter of the $this->load->view() function above. The reason you might want to use this function independently is if you would like to set some global variables in the constructor of your controller and have them become available in any view file loaded from any function. You can have multiple calls to this function. The data get cached and merged into one array for conversion to variables. "
Using $this->load->vars($data) helps in not having to load data for each view within my template.
use like this
$newData = array_merge($data, $data1, $data2);
$this->load->view('main', $newData);
If there are no key with same name in $data, $data1, $data2 then, it will work without modifying any of view for variable name change.

How to call the controller variable in view file using joomla?

I am new in joomla, My code is like this
//on controller
function listing()
{
JRequest::setVar( 'view', 'hello' );
JRequest::setVar('hidemainmenu', 0);
parent::display();
}
//on view.html.php
i want to fetch this 'hidemainmenu'
How can i fetch can anyone help??
If the code above is that of your view.html.php file then you can pass the variable through to your template file by using a line like so:
$this->assignRef( 'hidemainmenu', $hidemainmenu);
Then in your tmpl/default.php file for example you can access this variable like so:
$this->hidemainmenu
If the code is in the Controller :
get the Variable in the view.html.php
as
$hidemainmenu = JRequest::getVar('hidemainmenu');
Try this in the view.html.php or default.php

Resources