I'm using CakePHP (v3.0) and I want to show on screen the variable value.
I have tried to use print_r() function, but not always runs..
Whats would be the best option?
CakePHP comes with pr() function you can use that
Documentation link
I always use cake's debug() function, but you should consider using DebugKit for debugging your app.
DebugKit
Related
Is possible to change pagination url names in cakephp?
For example:
example.com/tests/act/page:2/sort:title/direction:desc
to:
example.com/tests/act/pg:2/link:title/orderby:-date
Thank you all. But I am beginner in cakephp and pleased to see an example.
I read the documentation. but there is nothing about things I want.
Maybe I can translate those parameters and give to the Paginator class. but how?
Yes. Use routing. http://book.cakephp.org/2.0/en/development/routing.html
Just create a rewrite rule for it.
Pagination Works with named parameters, and there is not a simple way to rename them. You will need to modify the PaginatorComponent and PaginatorHelper to modify the parameters of the pagination.
sorry i was new here so this problem maybe simple.
anyone knows how to check variable content?
like xx($a);
then page shows all relate information about $a. Is CakePHP allowed to do that?
i setup a kit on my cakephp
You might be looking for either var_dump() or print_r()
You can use PHP built-in functions like
var_dump() - displays structured information about variable
print_r() - the same, but preformatted with some differences
get_defined_vars() - returns array with all defined variables
Or use true CakePHP-way
Debugger::dump() - It will print out all properties and methods (if any) of the supplied variable
For more convenience you may use CakePHP Debug Kit plugin, which provides nice toolbar and some useful tools for your purpose.
Hi I have this sentence
$g->addButton('')->set('NEW ACTIVITY')->js('click')->univ()->redirect('newactivity');
Is it possible to call the "redirect" method and passing parameters via $_GET ? so in the page "newactivity" I can ask for $_GET['something'] ?
Something like this
$g->addButton('')->set('NEW ACTIVITY')->js('click')->univ()->redirect('newactivity?id=1'); (this doesn't work)
or
$g->addButton('')->set('NEW ACTIVITY')->js('click')->univ()->redirect('newactivity','id=1');
Thanks
What you need is to properly build destination URL.
http://agiletoolkit.org/learn/understand/page/link
->univ()->redirect($this->api->getDestinationURL('newactivity',array('id'=>1)));
using stickyGET will affect ALL the urls you are going to produce form this point on. So if you add 2 links, each of them would be passing ID.
stickyGET is better if you need to pass argument which was already passed through GET, such as
array('id'=>$_GET['id']);
Here is a place where other ATK4 Developers chat too, perhaps another resource for your ATK4 Q's. https://chat.stackoverflow.com/rooms/2966/agile-toolkit-atk4
I am using cakePHP v1.26.
In the default.ctp file,
I got a single of this code in it:
$session->flash();
I came a corss a web site in which the author suggested using this instead:
if($session->check('Message.flash')){
$session->flash();
}
I do not understand what this line of code is doing:
if($session->check('Message.flash')){...}
what is "Message.flash" in this case?
Is "Message.flash" a custom variable or
a built-in varibale which has been predefined in cakePHP?
Message.flash is the session variable name. It will be defined by cakephp, when you use $this->Session->setFlash('Your message'); from your controller.
if($session->check('Message.flash')){...} checks, if session Message.flash, which contains the flash message, exists.
Note also that contrary to the current manual description, $session->flash() does not echo the result, it just returns it, so you will need to have
echo $session->flash();
in your view.
For latest cakephp version
if(!($this->Session->check('Message.flash')));
// your code
In view section for show messages.
$this->Session->flash();
When using the paginator helper in cakephp views, it doesnt remember parts of the url that are custom for my useage.
For example:
http://example.org/users/index/moderators/page:2/sort:name/dir:asc
here moderators is a parameter that helps me filter by that type. But pressing a paginator link will not include this link.
The secret is adding this line to your view:
$paginator->options(array('url'=>$this->passedArgs));
(I created this question and answer because it is a much asked question and I keep having to dig out the answer since i cant remember it.)
To add to Alexander Morland's answer above, it's worth remembering that the syntax has changed in CakePHP 1.3 and is now:
$this->Paginator->options(array('url' => $this->passedArgs));
This is described further in the pagination in views section of the CakePHP book.
$this->passedArgs is the preferred way to do this from the view.
You saved me! This helped me a lot, Thanks.
I needed a way to pass the parameters I originally sent via post ($this->data) to the paging component, so my custom query would continue to use them.
Here is what I did:
on my view I put
$paginator->options(array('url'=>$this->data['Transaction']));
before the $paginator->prev('<< Previous ' stuff.
Doing this made the next link on the paginator like "
.../page:1/start_date:2000-01-01%2000:00:00/end_date:3000-01-01%2023:59:59/payments_recieved:1"
Then on my controller I just had to get the parameters and put them in the $this->data so my function would continue as usual:
foreach($this->params['named'] as $k=>$v)
{
/*
* set data as is normally expected
*/
$this->data['Transaction'][$k] = $v;
}
And that's it. Paging works with my custom query. :)
The options here are a good lead ... You can also check for more info on cakePHP pagination at cakephp.org/view/166/Pagination-in-Views
With that param 'url' you can only put your preferred string before the string pagination in url..
if I use this tecnique:
$urlpagin = '?my_get1=1&my_get2=2';
$paginator->options = array('url'=>$urlpagin);
I only obtain:
url/controller/action/?my_get1=1&my_get2=2/sort:.../...
and Cake lost my get params
Have you an alternative tecnique?