I have created a page using following link 1 in codeigniter.I have displayed the abstract in one line and author in second line using echo get_abstract($row->id=1).For second record i have to change id=2 and so on. Is there any way to create next and previous button in view so that when i click on next id would automatically get incremented and display record. Similarly for previous also.Right now I am using following view.php
<?php
if($fetch_data->num_rows() > 0)
{
$row = $fetch_data->row();
echo get_Author($row->DocumentID=1);
}?>
<?php
if($fetch_data->num_rows() > 0)
{
$row = $fetch_data->row();
echo get_Abstract($row->DocumentID=1);
}?>
You can see that i am using fixed id (DocumentID) to display records of 1st row of mysql.I want to change it dynamically by clicking next, previous in view rather than manually assigning.
The model and controller are defined in above link.I will be grateful to you for your help.
I have solved this problem by adding following model class and adding pagination in controller.
function fetch_data($limit, $offset=0)
{
$this->db->limit($limit,$offset);
$query = $this->db->get('prlaps');
return $query;
Related
I have a form to update an article.in this form I have tow select boxes one for section and another for sub section.An article should have a section but sub section is not necessary.In my update form if a section has subsections it should bring it.My problem is that in my update form if a section does not have any subsection it does not show the continuation of my form because in model it returns false.I tried to return null or an empty array but it could not solve my problem.
Model:
function get_subsection($sec_id,$subsec_name){
$this->db->selec("*");
$this->db->where('sec_id',$sec_id);
$this->db->where('subsec_name !=',$subsec_name);
$query=$this->db->get('sub_section');
if($query->num_rows() > 0)
{
return $query;
}
else
return false;
}
if this function returns false in update form it does not show the continuation of form and the edit submit button.I removed the else condition but it can not solve the problem.
Controller
function edit($id){
$data['rec']=$this->amodel->edit_art($id);//get the record to update
foreach($data['rec'] as $a)
{
$sections['items']=$this->amodel->section('$a->sec_id');//select all sections without that which selected by user
$subsetion['sub']=$this->amodel->subsection($a->sec_id,$a->subsec_name);//select all subsections of a section which selected by user
}
$this->load->view('edit_art',array_merge($data,$sections,$subsection));
}
the problem is with $subsetion which can has no record in database.
please guide me what should I do to show all form element even the subsection be empty.
If i understand ur problem then you can try this
Model:
function get_subsection($sec_id,$subsec_name){
$this->db->selec("*");
$this->db->where('sec_id',$sec_id);
$this->db->where('subsec_name !=',$subsec_name);
$query=$this->db->get('sub_section');
return $query->result();
Controller:
function edit($id){
$data['rec']=$this->amodel->edit_art($id);//get the record to update
foreach($data['rec'] as $a)
{
$data['items']=$this->amodel->section('$a->sec_id');//select all sections without that which selected by user
$data['sub']=$this->amodel->subsection($a->sec_id,$a->subsec_name);//select all subsections of a section which selected by user
}
$this->load->view('edit_art',$data);
}
View :
<?php echo form_dropdown('items',$items,"",'class=""'); ?>
<?php echo form_dropdown('sub',$sub,"",'class=""'); ?>
Let me know is it ok or not. if not ok then post your view code.
Try the following:
function edit($id){
$data['rec']=$this->amodel->edit_art($id);//get the record to update
foreach($data['rec'] as $a){
if($this->amodel->count_sections($a->sec_id) > 0)
$sections['items']=$this->amodel->section('$a->sec_id');//select all sections without that which selected by user
else
$sections['items'] = NULL;
if($this->amodel->count_subsections($a->sec_id,$a->subsec_name) > 0)
$subsetion['sub']=$this->amodel->subsection($a->sec_id,$a->subsec_name);//select all subsections of a section which selected by user
else
$subsetion['sub']= NULL;
}
$this->load->view('edit_art',array_merge($data,$sections,$subsection));
}
Count the number of available sections and subsections and try to read the records if they are avalable!
Write the required functions (count_sections and count_subsections) in the model!
I am working with a magento website. I have used a featured category to display homepage slider products. So when I click on the product it shows featured as a category in the breadcrumb.
Would it be possible not to show featured in the breadcrumb ? I want category name in the breadcrumb for the rest of categories .
Thanks
Ab
actually not getting your question but you can get some idea from here:
in page/html/breadcrumb.phtml file near line 34-36 change, $_crumbInfo['label'] to $_crumbInfo['title']
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['title']) ?></strong>
then in catalog/block/breadcrumb.php add 2 lines after
$path = Mage::helper('catalog')->getBreadcrumbPath();
$currentCategory = Mage::registry('current_category');
$metaname = $currentCategory['name'];
and change foreach loop like
foreach ($path as $name => $breadcrumb) {
$breadcrumb['title'] = $metaname;
$breadcrumbsBlock->addCrumb($name, $breadcrumb);
$title[] = $breadcrumb['label'];
}
and check it,
hope you get some idea..
Why no simpler than that?
Try to use CSS. Your category will have an automatic and specific class for it. For example:
<li class="category4">
<strong>ARCHERY HUNTING</strong>
</li>
In this piece of code, I have a category that I created, called "Archery hunting". The code auto-created the class="category4", So, only write on your CSS:
.category4 strong { display: none; }
And it will hide only that category.
Instead of using
$_product->getProductUrl()
to fetch URL, use this:
$_product->unsRequestPath()->getUrlInStore(array('_ignore_category' => true))
Then you need to unset last visited category id at the end of your featured block:
Mage::getSingleton('catalog/session')->setLastVisitedCategoryId('');
This is all because key part for forming breadcrumbs is the following code:
$categoryId = $params->getCategoryId();
if (!$categoryId && ($categoryId !== false)) {
$lastId = Mage::getSingleton('catalog/session')->getLastVisitedCategoryId();
if ($product->canBeShowInCategory($lastId)) {
$categoryId = $lastId;
}
}
basically, current category is determined by either URL params (hence the modified URL call), or through the session object (hence the removal of last visited category id)
so, to recapitulate, in your Featured block, instead of regular productUrl call, use the one I provided, and at the end of your featured product block listing, remove the lastVisitedCategoryId using the code I gave you
I'm very new to CI. :)
In my project, I have separated the page into header, footer and body. And the body portion(view) is loaded based on the controller. The header and footer are common to all pages.
For example, for a login page it would be like this:
$this->load->view('header');
$this->load->view('login');
$this->load->view('footer');
But now my concern is, how to generate the "category" section (which will list several category names on the left of the body portion). Upon clicking a category, the corresponding details page would be show to the right(ie. in content portion). So, in all views(all pages) I need to display the list of categories.
Visual example:
----------------------------
Header Portion of Page
----------------------------
Body Portion
============
Cat1 |
Cat2 |
Cat3 | Content
Cat4 |
Cat5 |
----------------------------
Footer
----------------------------
These categories are populated from the data in db.
I have just done some searching. So, I am thinking about creating a helper class and autoload it. So, in all views, I would call the function and and echo the result.
For eg:
function hlp_getCategories()
{
$ci =& get_instance();
$q = $ci->db->query('SELECT cat_name FROM tblCategories');
return $q;
}
And in the view:
<?php
$q = hlp_getCategories();
foreach ($q->result_array() as $row)
{
echo anchor('cat/' . $row['cat_name'], $row['cat_name']) ;
}
?>
Is this the correct approach ?
Am I in the right track ?
Thanks in advance :)
That is one way to solve it - although if you follow a strict MVC approach - the helper would call the model $this->category->select_cat(), and put the SQL query in the model. Furthermore, the SQL query should use active record selections, not a text SQL query.
The other way to solve it is to use some CSS that has a DIV for the left menu (i.e. categories), and a DIV for the right (i.e. content).
Then you could do
$this->load->view('header');
$this->load->view('categories');
$this->load->view('login');
$this->load->view('footer');
Then inside your categories view
<div class = "left">
// show categories here
</div>
and inside your content views
<div class = "right">
// show content here
</div>
Ive been working with CI and I saw on the website of CI you can load a view as a variable part of the data you send to the "main" view, so, according the site (that says a lot of things, and many are not like they say ...ej pagination and others) i did something like this
$data['menu'] = $this->load->view('menu');
$this->load->view ('home',data);
the result of this is that I get an echo of the menu in the top of the site (before starts my body and all) and where should be its nothing, like if were printed before everything... I have no idea honestly of this problem, did anybody had the same problem before?
Two ways of doing this:
Load it in advance (like you're doing) and pass to the other view
<?php
// the "TRUE" argument tells it to return the content, rather than display it immediately
$data['menu'] = $this->load->view('menu', NULL, TRUE);
$this->load->view ('home', $data);
Load a view "from within" a view:
<?php
// put this in the controller
$this->load->view('home');
// put this in /application/views/home.php
$this->view('menu');
echo 'Other home content';
Create a helper function
function loadView($view,$data = null){
$CI = get_instance();
return $CI->load->view($view,$data);
}
Load the helper in the controller, then use the function in your view to load another one.
<?php
...
echo loadView('secondView',$data); // $data array
...
?>
I'm trying to display an image but is dependent on a dropdown list in Yii. I can get the image from the database and display it, but how to do it dynamically depending on the choice from the dropdown?
Here is the reference: http://www.yiiframework.com/wiki/24/creating-a-dependent-dropdown#hh0 but, let me show you how to do it.
First all all, we need a div where the image will be displayed; I'll create one whose id will be 'img'. Then, the ajax request is specified inside the dropdownlist() as follows:
<?php echo $form->labelEx($model,'attribue'); ?>
<?php echo $form->dropDownList($model,'attribute',
array(/*The options in the DropDownList*/),
array(
'ajax'=>array(
'type'=>'POST',
'url'=>CController::createUrl('YourController/actionWhichEchoesTheImage'),
'update'=>'#img',
)));
?>
<div id="img"> // <---- the result of the ajax call will be displayed here
</div>
In the 'url' attribute we specify the function which will be called when the ajax request triggers. In the 'update' attribute we specified the div where will be displayed the result of calling that function (the image).
Finally, we have to declare the action actionWhichEchoesTheImage(). Let's declare it in the current controller. It would look something like this:
public function actionWhichEchoesTheImage()
{
if(isset($_POST['ModelName']['attribute']))
/*Here goes your code to load the image*/
echo CHtml::image(//Check the reference to see how to set this function);
}
Check CHtml::image() here: http://www.yiiframework.com/doc/api/1.1/CHtml/#image-detail