Zend Framework problem with Zend_Layout - php

How can I create something like: $this->layout()->sidebar, I'm trying for about 4 hours...but it doesn't work for me!Can you give me an example?

I'm still not certain what you are trying to do - but maybe this code that I'm using would help.
// setup the info column into the placeholder
$this->placeholder('rightcol')
->set($this->render('index/view_infoCol.phtml'));
// later in the layout template
echo $this->placeholder('rightcol');

use setResponseSegment('sidebar') in you controller to make $this->layout()->sidebar work...

You could use this:
In your controller:
$this->_response->insert('sidebar', $this->view->render('sidebar.phtml'));
In your layout:
<?=$this->layout()->sidebar;?>

Related

Laravel paginate() method is not working with the distinct() method

My Laravel code is something like this...
Cheque::distinct()->get(['cheque_no'])->paginate('25');
If possible I want to add sortByDesc('updated_at') also.
Please help me.
First off, I think you want
distinct('cheque_no')->get()
instead of
distinct()->get(['cheque_no'])
Then, either you use get or paginate
And you define the sorting at the end
So, the altogether ends up like this:
Cheque::distinct('cheque_no')->paginate(25)->sortByDesc('updated_at');

fuelphp - how can I add a custom path to the asset class?

Ok,
So quick question that is driving me crazy with FuelPHP
For css, js, and img assets I can do this in a view
<?php echo Asset::css('main.css'); ?>
But if I try to add a folder - for example - "media" to the public/assets directory I can not do this:
<?php echo Asset::media('myvideo.mp4'); ?>
Does anyone know if there is a way to configure that kind of functionality? Has anyone been able to modify the asset class to do that?
Thank you very much for your time and help!
I don't know if there is such fashion that you could create your own static method name (the one you like is media as I haven't tried it yet). But you declare that path instead. Consider this example:
(file is in public/assets/media/file.mp4)
Controller
Asset::add_path('assets/media/', 'media');
View
Video 1
You can easily create such methods by extending the core class.
This can not be solved generically (for example with a magic __call()), because the class would not know which HTML to generate for "media" (or whatever you want to add).

How to auto-instantiate a library in CodeIgniter

I'm using a really basic library in Codeigniter. In order to use it I need to pass in a number of config parameters using a config function. My library currently requires me to instantiate it before I can call the config, i.e., I have to use it as below:
$this->load->library('Library');
$instance = new Library();
$instance->config($configparams);
I'd like to use it like standard CodeIgniter libraries:
$this->load->library('Library');
$this->library->config($configparams);
What do I need to add to the library in order to have it auto-instantiate? The code is as below:
class Library {
function config($configparams){
...
}
}
This is working now. I swear it wasn't working before I posted on SO! Thanks for posts.
Once you load a class
$this->load->library('someclass');
Then when use it, need to use lower case, like this:
$this->someclass->some_function();
Object instances will always be lower case
According to the docs, you should just call it. So:
$this->load->library('Library');
$this->library->config($configparams);
But why not just pass $configparams to the constructor:
$this->load->library('Library', $configparams);
Check out the guide for CodeIgniter -- it's a great resource to learn more about the framework. IMHO, there aren't any good books available on the current version; this is it.
You basically call it like anything else.
$this->load->library('Name of Library')
Read more here: http://www.google.com/url?sa=t&source=web&cd=2&ved=0CCIQFjAB&url=http%3A%2F%2Fcodeigniter.com%2Fuser_guide%2Fgeneral%2Fcreating_libraries.html&ei=tLFUTbz3HI3SsAOYgP2aBg&usg=AFQjCNFo751PYFp5SbqzuZMxGhXwMI8SJA

CakePHP Pagination - how to remove "page:" from url for better seo/cleaner URL

When I use CakePHP Paging I get an url like this:
http://example.com/php/page:2
What do I have to change in the controller, the view and the routes.php to create a working url like this:
http://example.com/php/2
Oh yes, now I see your question. Well you could do something like:
function index($page){
$this->paginate = array('page'=>$page);
$this->set('stuff', $this->paginate('YourControllerName'));
}
See here for more details:
http://bakery.cakephp.org/articles/view/basic-pagination-overview-3
Also, of course you should do some validation that the page is an actual number and that the page would even exist but that is the basics of it i think.
About the routes and views, I have never tried but have a look at these posts on the cake groups, I think they have a problem similar to yours.
http://www.mail-archive.com/cake-php#googlegroups.com/msg45878.html
Try this link:
http://www.sakic.net/blog/changing-cakephp-pagination-urls/
My guess is that this won't be easy to automate, you'll definitely need to do some tweaking.
For starters, you'll probably have to create your own paginator helper and inherit the default one. By the looks of the code, you'll need to override the link-generating code in PaginatorHelper::__pagingLink(), but probably numbers() and prev() etc.. since they all create links with the page param.
Maybe a better way would be to override your AppHelper::url(), check for the "page" param there and modify the url to accomodate your needs.
But, I haven't tried all this, so no guarantees..

Getting parameters in YII from URL

I'm total newbie on Yii. Professor basically asks us to make school project having shown us three things to do in Yii.
Let's observe two classes I have, their models being: StudProg and NivoStudija.
What I want is to pass attribute 'naziv' from nivoStudija/admin to studProg/admin, because when I click on a particular item nivoStudija/admin, studProg/admin is shown and I want to use this variable there. So I pass argument like this in one of my CGridView widget's items:
CHtml::link($data->naziv, array("studProg/admin", "nivo_naziv" => $data->naziv))
It opens up studProg/admin and I see URL like this:
http://localhost/pmf/index.php?r=studProg/admin&nivo_naziv=Osnovne+studije
My problem is: How do I get this nivo_naziv thing to use it in studProg/admin ?
Thanks in advance.
For Yii1 you need the equivalent code
$my_nivo_naziv = Yii::app()->request->getQuery('nivo_naziv);
I'm assuming that you are using Yii2.
Then you can get the URL parameter with:
Yii::$app->getRequest()->getQueryParam('nivo_naziv');
Try this for Yii1:
Yii::app()->getRequest()->getParam('nivo_naziv');
In Yii if you want to access get and post parameter, you can use getParam function like this.
Yii::app()->request->getParam('nivo_naziv);
http://www.yiiframework.com/doc/api/1.1/CHttpRequest

Categories