I'm using codeigniter for make dynamic website. In news page, I use url method like: http://test.com/test/test/news_details?id=27
how can i change my url to put news title within ?id=27
example:
http://test.com/test/test/news_details/pass-this-url
"pass-this-url" refer to id=27.
Best Regards.
Use routes : http://www.codeigniter.com/user_guide/general/routing.html
In your case it will be something like this :
$route['pass-this-url'] = "test/test/news_details?id=27";
So http://www.example.com/pass-this-url will be understand by codeigniter as http://www.example.com/test/test/news_details?id=27
however, if you want to make it dynamic, you will have to call your db :
require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$query = $db->get( 'news' );
$result = $query->result();
foreach( $result as $row )
{
$route[$row->title] = "test/test/news_details?id=". $row->id;
//We suppose here that your title is URL friendly.
}
Go to application/config/config.php and check this:
$config['enable_query_strings'] = FALSE;
Related
$base_where = $this->input->post('f_OrderNumber') ? $base_where + array('OrderNumber' => '*' . $this->input->post('f_OrderNumber') . '*') : $base_where;
$orders = $this->orders_m->get_many_by($base_where);
Except I want the OrderNumber to be LIKE the POST
If your "orders_m" model is extending from MY_Model (which it probably is), you can use all the standard Codeigniter Active Record functions.
if( $this->input->post('f_OrderNumber') )
{
$this->orders_m->like('OrderNumber', $this->input->post('f_OrderNumber'));
}
$orders = $this->orders_m->get_all(); // if you want everything OR
$orders = $this->orders_m->get_many_by('field', 'value'); // if you have other parameters
How do we render module in joomla with the title. Because now, I am able to render the module based on the position but it does not include the module title.
Here's how I render the module.
<?php
jimport('joomla.application.module.helper');
$modules = JModuleHelper::getModules('position-3');
foreach ($modules as $module) {
echo JModuleHelper::renderModule($module->title);
echo JModuleHelper::renderModule($module);
}
?>
Many Thanks.
Try this,
Using this method you can pass parameters to the module .
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$Module = JModuleHelper::getModule('mod_fmDataGrid');
$Params = "param1=bruno\n\rparam2=chris"; //This is the way of passing params values
$Module->params = $Params;
echo $renderer->render($Module);
Hope it helps..
Try using the following:
foreach ($modules as $module)
{
echo $module->title;
echo JModuleHelper::renderModule($module);
}
You can also use the following, however you will have to manually enter the module title. This is only assuming you don't want it to be dynamic. You will also need to change mainmenu
$module = JModuleHelper::getModule( 'mainmenu', 'Module Title Goes Here' );
echo JModuleHelper::renderModule( $module );
Try this.
Hope this will work for you.
$document = JFactory::getDocument();
$renderer = $document->loadRenderer('module');
$contents = '';
$db = JFactory::getDBO();
$db->setQuery("SELECT * FROM `#__modules` WHERE id = 'your module id'");
$modules = $db->loadObjectList();
$module = $modules[0];
$contents = $renderer->render($module);
What would be the code to display articles from category (specified by ID)?
In Wordpress this is fairly easy by doing:
<?php
query_posts('cat=1');
while (have_posts()) : the_post();
the_title();
endwhile;
?>
I'm looking for similar code for Joomla.
$db = JFactory::getDbo();
$id = 50;//example
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__content');
$query->where('catid="'.$id.'"');
$db->setQuery((string)$query);
$res = $db->loadObjectList();
foreach($res as $r){
echo '<h3>'.$r->title.'</h3>';
echo $r->introtext;
}
You can use next code template:
$categoryId = $[category id];
require_once("components/com_content/models/category.php");
$category = new ContentModelCategory();
$category->hit($categoryId);
$articles = $category->getItems();
print_r($articles);
There is no direct code for getting this in joomla like word press.
If you want to check the code you can check the code for achieving this by following path.
components/com_content/view/category/view.html.php
and
components/com_content/view/category/tmpl/blog.php
According to my Guess your requirement is to display the articles from same category.
then in joomla you dont need to edit in any code.
for achieving this you can simply create a menu.
and menu layout type should be category blog and Choose your category from the right side category options.
This will get the complete article from that category.
If you want to manage it in your style you can add style based on blog.php file .
Hope this will help you..
Try this:
$articles = JFactory::getDBO()->setQuery("SELECT * FROM #__content WHERE catid = '21'")->loadObjectList();
Of course replace '21' with id of your category.
This is quite easy in Joomla. You can find the code in /components/com_content/models/category.php under getItems()
Below is an example
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState('params', JFactory::getApplication()->getParams());
$model->setState('filter.category_id', $category_id);
$articles = $model->getItems();
How can I find the correct SEF url of an Menuitem, based on its ID?
$link = JRoute::_( $menus->getItem( $id )->link.'&lang='.$languages[ $code ]->sef, true );
delivers something like:
http://localhost/<path>/component/content/?view=featured
but what i want is the url generated from the menu, which is:
http://localhost/<path>/<lang-sef-code>/<path>
How can I achive this?
I finally found the solution for the problem I had.
$languages = JLanguageHelper::getLanguages('lang_code');
foreach ($associations as $code => $id ) {
item = $menus->getItem( $id );
$link = JRoute::_( 'index.php?lang='.$languages[ $code ]->sef.'&Itemid='.$item->id );
}
this delivers:
http://localhost/<lang>/<path-to-link>
I noticed that when dealing with SEF URLs than the order in which vars are given to the JRoute::_() method are decisive. I hope to help somebody who got some problems with this too.
Greetings
philipp
I am use following code to retrieve the session variable in routes.php
if($this->db_session->userdata('request_url')!="")
{
$route['user/(:any)'] = "search_user_name/redirect_url/".$_SESSION['request_url'];
$this->db_session->unset_userdata('request_url');
}
else {
$route['user/(:any)'] = "search_user_name/index/$1";
}
the session variable would be set into template/header.php
$this->db_session->set_userdata('request_url', $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]);
You can not use db_session in routes.php because routes.php is parsed before db_session is loaded.
Maybe you should create a base controller and redirect from the constructor of the base controller.
Correct me if iam wrong.
You can use hooks.
Codeigniter user guide hooks
You can use database in routes and put your routes url in database.
Here is an example:
require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$table2 = $db->dbprefix.'lang';
$query2 = $db->get( $table2 );
$result2 = $query2->result();
foreach( $result2 as $row )
{
$fields = $db->list_fields($table2);
$findme = 'code';
foreach($fields as $field):
$pos = strpos($field, $findme);
if($pos !== false and $row->$field != ''):
$route[''.$row->$field.''] = 'main/setlang/$1';
endif;
endforeach;
}