I have one controller called "site" which is a default controller. I want to display all the post from my database. So whenever users go to my site, they can see all the posts. I have removed "index.php" and URL rewriting on through .htaccess.
There are two buttons called latest and popular and also some categories on that page. I just want whenever user click on latest or popular button or any category I want to pass the data directly to the default controller like this way-
http://example.com //Show all post from all categories
http://example.com/latest //Show the latest post from all categories
http://example.com/popular // Show the popular posts from all categories
http://example.com/health //Show all post from category health
http://example.com/health/latest //Show latest post from category health
http://example.com/health/popular //Show popular post from category health
Now my questing is how to write the routing part.
This is my default routing
$route['default_controller'] = 'site';
and here is my index method of site controller
public function index($cat=null, $type=null)
{
//The other logic here
}
Related
I am a beginner in CodeIgniter and want to internally link my a tag on homepage to element with id="gainers" on products page.
I have tried many sources on the net, documentation of CodeIgniter (Views), and videos on youtube but could not get help. My controller has this code.
public function toLoadProductsPageGainers()
{
$this->load->view('vsc_spl_product_from_model#gainers');
}
where "gainers" is the id of a segment on the products page.
I want the link which is calling toLoadProductsPageGainers() from my homepage to lead to id="gainers" on the products page. But 404 error is coming.
html code should be
Go To Link
While your controller should be like below
public function toLoadProductsPageGainers()
{
$this->load->view('vsc_spl_product_from_model');
}
I have a working project on Codeigniter 3. Now I have to build a FAQ page and I had this doubt: do I need a Controller for every URL?
It is, the FAQ page is a static page, but CodeIgniter generally routes URLs to Controllers, like domain/controller/method. But it seems a waste to build a Controller to only load the View.
No, it's not right way to make controller for every page. Just make one function which shows page by fetching data from database.
First of all make a table named pages in your database then save page_content, page_name, permalink for your different pages.
Now suppose your default controller is home, make a function in it with name page as below.
function pages( $permalink )
{
// get page data based on page_name passed in URL
$this->db->where( array( 'permalink' => $permalink ) );
$data['page'] = $this->db->get( 'pages' )->result();
// load view and pass page object to view
$this->load->view( 'view_file', $data );
}
Now same function will show different page content based on permalink passed in URL.
For example if URL is www.example.com/index.php/home/pages/faq then content of faq page will be shown.
I am using Joomla 3.x CMS. I have SEO enabled. I am also routing the URL so that article IDs, category and category IDs are hidden. Hence a typical article with an alias of my-alias will have the URL: http://localhost/my-alias. I am doing this routing in a system plugin in method onAfterInitialise(). All aliases in the system are ensured to be unique. Now when an article is being viewed, anyone with access will see an edit URL as follows: http://localhost/my-alias?task=article.edit&return=someValidToken. This too is routed properly to the actual article to be edited.
When viewing an article, the user/browser does not see the article ID (as desired). When editing, the user/browser sees the article ID (not what I want). That is, when user clicks the edit link, browser loads the edit form and user sees the following URL: http://localhost/edit-article?view=form&layout=edit&a_id=1002&return=someValidToken, where 1002 is the article ID.
Following is a code snippet from onAfterInitialise():
if (isset($query['task']) && $query['task']=='article.edit') {
// TODO Hide this change from the user/browser
JFactory::getApplication()->input->set('view', 'form');
JFactory::getApplication()->input->set('layout', 'edit');
JFactory::getApplication()->input->set('a_id', $articleId);
}
else {
JFactory::getApplication()->input->set('option', 'com_content');
JFactory::getApplication()->input->set('view', 'article');
JFactory::getApplication()->input->set('id', $articleId);
}
JFactory::getApplication()->input->set('Itemid', 111); // map to dummy item in hidden menu with alias edit-article
I would like to know how to solve this. An understanding of the call flow through the Joomla framework will help.
Is there a way to change the Url generated by the LinkPager in Yii2?
I have a page with results that are loaded with ajax when the search field is updated. But my pagination buttons links to a new page with the ajax-call url.
I looked in the files, and it seems like this function generates the url
public function createUrl($page, $pageSize = null, $absolute = false)
and that is not option to change. What is the way to solve this problem?
My results page is at the front page, but the pagination buttons links to ajax/results?page=2&page-size=10.
What can be more elegant then extending a class and replacing the renderPageButton function with your own :).
Another way, probably more the yii2 way :) if you take a look at LinkPager you will see that it is not responsible of creating the URLS. Pagination is https://github.com/yiisoft/yii2/blob/master/framework/data/Pagination.php#L257 The createUrl function in Pagination creates the URL and it takes into consideration the $route defined for the pagination object. If there is no $route defined then it takes the current controller's route. So by setting up $route for the pagination you can set the URL the buttons will go to.
I am working on a module for video gallery. I can add category from the back end and can upload video with respect to that category.
I can modify the category listing page using <frontname></frontname> in config.xml
I have also noticed that the url of every category in category listing page is managed from model/category.php and the function is:
public function getCategoryUrl()
{
return Mage::getUrl('videogallery/index/cat', array('ci' => $this->getCategoryId()));
}
where videogallery is module name, index is controller name and cat is catAction function in indexController.php, So my every category url is like www.domainname.com/module-Frontend-name/index/cat/ci/categoryId
My question is how can I remove this "index/cat" from every category url?
if "cat" is the name of your action inside IndexController, there's no way to remove it, unless you code a mod_rewrite rule.
Is this what you need?