Codeigniter custom URL structure - codeigniter

I want Url in my codeigniter app like this,
in Home www.domain.com/ -> i route the $config defaut_controller to category
in page 2, www.domain.com/category/[category_name]/ -> in here (page 2) i create pagination.
in page 3, www.domain.com/category/[categori_name]/[sub_category1_name] ->in here i create pagination too.
and then, in page 4 i want www.domain.com/category/[categori_name]/[sub_category1_name]/[sub_category2_name].
In my database, I have table category, sub_category1, sub_category2. and string url in every table.
I was try using _remap($method, $params = array()) function, but i can't do it.
Can anybody give me approch to do this? or reference similar web structure.

You can use routes for this.
In application/config/config.php:
For page 1:
$route['default_controller'] = 'category';
For page 2:
$route["category/(:any)"] = "category/index/$1";
For page 3:
$route["category/(:any)/(:any)"] = "category/index/$1/$2";
For page 4:
$route["category/(:any)/(:any)/(:any)"] = "category/index/$1/$2/$3";
Side note:
If you still facing the issue than create seperate function in category controller for sub_category and change index to function name in controller.

Related

Routing issues with Codeigniter project

In my routes.php file I have the following codes:
$route['admin/login'] = 'admin/login/index';
$route['admin/add_client'] = 'admin/add_client/index';
$route['(:any)'] = function ($val){
require_once( BASEPATH .'database/DB.php' );
$db =& DB();
$db->select('url');
$db->from('interior_form');
$db->where('url',$val);
$query = $db->get()->row();
$db->close();
if(sizeof($query)>0):
return 'home';
else:
return "404_override";
endif;
The issue that I am facing here is whenever I put www.xyz.com/admin/login , it goes to the home page first then again if I write www.xyz.com/admin/login in the same browser, only then it goes to the admin login page.It does not go to the admin login page on the very first instance.
Try:
$route['admin/login'] = 'admin/login/index';
$route['admin/add_client'] = 'admin/add_client/index';
$route['(:any)'] = 'home/$1';
In your home controller, there you handle which request is 404 and which is valid.
You don't need to edit your Rout file.first of all come out from that file.
and you can do this.....
In admin controller page create a function called index.in that function you load your login page.
whenever you type www.xyz.com/admin then load the admin login page.
note:-
Which controller page contains index function,first that index function is load when call that controller, because of index function is first priority compare to other functions in all controllers page.
You may try this simple code for set up rout as bellow.
$route['default_controller'] = 'Adminlogin';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

how to make codeigniter routing to work with paging

I have the following routes for the news that works like a charm:
$word5 = urlencode('mygreek-keyword-here');
$route[$word5] = "news/displayAllNews";
and this page display all news with the desired keyword in the address bar. But...there is always a but...I have paging on this page, so when i click on next page link...page works but with old non-friendly seo url, that is:
news/displayAllNews/10/10
while I would like to have is: mygreek-keyword-here/10/10
code that i have in my controller for the paging is as follow:
$config['base_url'] = site_url('/news/displayAllNews/'.$limit.'/');
what should i do in routes.php and in my controller to get the desired result?
Regards, John
You could get the string of URI by $this->uri->uri_string() method, and set the pagination config as follows:
$config['base_url'] = site_url($this->uri->uri_string() .'/'. $limit.'/');
Note that the URI library is loaded automatically, it doesn't need to load it manually.
Update:
Change the route rule to:
$route["$word5(.*)"] = "news/displayAllNews$1";
If it doesn't work yet, remove the .'/'. $limit.'/' phrase and let the pagination to add the limit itself by:
$config['per_page'] = 10; // or $limit, default items per page.
$config['use_page_numbers'] = FALSE;

Codeigniter admin controller in subfolder issue while pagination

I am new to codeigniter.i have create subfolder for admin controller like
Controller->admin->news.php
Now when i am access the news controller its working fine like
http://mysite.com/sacha/adminenter code here/news
But when i am trying edit delete or pagination like
http://mysite.com/sacha/admin/news/index/1
or
.../sacha/admin/news/1
Its showing 404 page not found error
Routes which i am using is
$route['admin/news'] = 'admin/news';
$route['admin/news/index'] = 'admin/news/index';
$route['admin/news/(:num)'] = 'admin/news/$1';
$route['admin/news/index/(:num)'] = 'admin/news/index/$1';
I used (:any) also but none is working.
Thanks
remove your four line you specified above and just update your routes as this,.
$route['admin/news/index/(:num)'] = 'admin/news/index/$1';
$config['uri_segment'] = 4;
You have to include this config parameter in pagination.

How can I get the CMS page id of a particular page in Magento

In magento by using this code:
$currentPageId =$this->getRequest()->getParam('page_id');
we can get the current page id.
But how can I get the page id of a particular page?
For example, I have a page with URL key about-fruit-store.
I want to get its page id. How can I get it?
Either
$model = Mage::getModel('cms/page')->load('about-fruit-store','identifier');
var_dump($model->getData());
var_dump($model->getPageId());
or
$model = Mage::getModel('cms/page')->getCollection()
->addFieldTofilter('identifier','about-fruit-store')
->getFirstItem();
var_dump($model->getData());
var_dump($model->getPageId());
should do it.

In codeigniter how to pass the array values to the same view page from controller?

I am new to codeigniter. with the help of jquery and ajax i am using multiple drop down list for selceting cities and categories. for selecting cities i have already loaded the view page "index" and passed values from the controller as:
$this->load->view('index',$data);
but now for selecting categories, again i want to pass values and load the index view page.i have used as.
$this->load->view('index',$arrCategory);
$arrCategory is an array. now the problem is, the index view page is loading within the same index view page. But i can able to get the array values in view page.
Thanks in advance..
You can do:
$data = $other_datas;
$data['arrCategory'] = $arrCategory;
$this->load->view('index',$data);
For more clarification
$data['otherData'] = $other_dropdown;
$data['arrCategory'] = $arrCategory;
$this->load->view('index',$data);

Resources