How I can active $record - codeigniter-2

I have table like this
public function getDoctorPhotoRecord($count)
{
$this->db
->select('u.id, fullname, image, unvan_code, baslik, onayli')
->from('user as u')
->join('user_detail as ud', 'u.id = ud.id')
->join('tanim_sehir as us', 'ud.sehir_code = us.code')
->where('group', 'doktor')
->where('image != \'\' ')
->order_by('rand()')
->limit($count);
$query = $this->db->get();
return $query->result_array();
}
and I want this code work as
<?php
$onay = $record->detail->onayli;
?>
<?php
if ($onay == 0) {
?>
<i class="fa fa-user-md" aria-hidden="true"></i> Bu <b>Doktor</b> siz misiniz?
<?php
} else {
?>
<span class="verified" id="verifyuser" title="" data-toggle="tooltip" data-placement="bottom" data-original-title="Onaylı Üye"><i class="fa fa-check"></i></span>
<?php
}
?>
When I tried it getting data with this :
<?php echo $item['onayli'];?>
but I want active This code
<?php
$onay = $record->detail->onayli;
?>
How I can active this code ?
Thank you

Related

How do i retrieve images from folder which is linked to an item id?

The main issue is with the model, i cant figure out how to join the two tables so that i can display an item with its image which are stored in different locations.
model
$this->db->select('bs_items.id, bs_items.description, bs_items.title,
bs_items.touch_count,bs_items.price');
$this->db->from('core_images');
$this->db->join('bs_items', 'core_images.img_parent_id =
bs_items.id');
$this->db->order_by('bs_items.touch_count', 'desc');
$this->db->from('bs_items');
Controller:
this->load->model('Popular_car');
$this->load->model('Recent_car');
$data['popular_cars']= $this->Popular_car->popular_car();
$data['recent_cars']=$this->Recent_car->get_listing();
$this->load->view('templates/header');
$this->load->view('pages/home', $data);
$this->load->view('pages/home_recent', $data);
$this->load->view('templates/footer');
Please update your question with some code you have done , or database structure. i'm giving you the answer based on what i understood using your given code snippet.
Model
function get_items()
{
$this->db->select('*');
$this->db->from('core_images');
$this->db->join('bs_items', 'core_images.img_parent_id =
bs_items.id');
$this->db->order_by('bs_items.touch_count', 'desc');
$query = $this->db->get();
return $query->result();
}
Controller
function get_allitems()
{
$this->load->model('model_name');
$data['items'] = $this->model_name->get_items();
$this->load->view('view_name', $data);
}
View
<?php foreach ($items as $row): ?>
<h1><?php echo $row->title;?></h1>
<p><?php echo $row->touch_count;?></p>
<p><?php echo $row->price;?></p>
<p><?php echo $row->description;?></p>
<img src="<?php echo base_url().'path_of_image/'.$row->image_from_db; ?>
<?php endforeach; ?>
$myString = $this->db->get_where('profile_table' , array('id' => $edit ) )->row()->file_name_galery;
// $json11 = '{ "1":"s1.jpg", "2":"s2.jpg", "3":"s4.jpg", "4":"s4.jpg", "5":"s5.jpg" }';
$array = json_decode($myString);
if (empty($array)) {
echo '<p class="tx-danger"> NO IMAGE..</p>';
}
foreach($array as $key => $photo) { <div class="column_galery text-center zoom_img_app">
<a onclick="selected_photo(' echo $photo; ')" data-toggle="modal" data-target="#edit_image_mod" >
<img class="" src="http://yourapp.com/uploads/profile_gallery/ echo $photo; " style="width:100%"> <span class="tx-danger">DELETE</span> </a>
</div> }

Show all subcategories of current parent caregory in sidebar navigation in MAGENTO

Trying to build sidebar category structure in Magento so that all children for an active category show when clicked. Using below as sample, when you go into main catalog only Main Cats appear. Then when clicking any Sub Cat the children for that respective category appear and so on.
For example
Main Cat 1
Sub Cat 1
Sub/Sub 1
Sub/Sub 1
Sub/Sub 1
Sub Cat 1
Sub Cat 1
Main Cat 2
Main Cat 3
Here's the current code I have, but once you get to the last category, only the Main Cats show (in other words, if you click on Sub/Sub, the menu closes and shows only the Main Cats).
<aside id="sidebar">
<div class="sidebar-nav">
<h2><?php echo $this->__('Products') ?></h2>
<ul>
<?php foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li>'.$cat->getName()."<ul>";
foreach ($obj->getCurrentChildCategories() as $subcat) {
echo '<li>'.$subcat->getName()."</li>";
}
echo "</ul></li>";
} else {
echo '<li>'.$cat->getName()."</li>";
}
} ?>
</ul>
</div>
<div class="sidebar-nav">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('holiday-nav-links')->toHtml() ?>
</div>
<div class="sidebar-nav">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('about-us-nav-links')->toHtml() ?>
</div>
</aside>
Any help is much appreciated. Thank you in advance for the help!
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Please check this link http://fishpig.co.uk/magento/tutorials/display-categories-and-subcategories-in-magento/
hope this help you
Had to do this very thing a few days back . get my whole function, may include some unnecessary html parts though. Shows 2nd level categories level onwards (for 3rd level category view as well)
public function getCatTree()
{
$treeHtml = '';
$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
$category = Mage::registry('current_category');
$level = $category->getLevel();
switch($level)
{
case 4 :
$level3Cat = $category->getParentCategory();
$level2Cat = $level3Cat->getParentCategory();
break;
case 3 :
$level2Cat = $category->getParentCategory();
break;
case 2 :
$level2Cat = $category;
break;
default :
$level2Cat = null;
break;
}
//get the level 2 category ID
$categoryId = $level2Cat->getId();
if (count($_categories) > 0)
{
foreach ($_categories as $_category)
{
//match with the level 2 category, then list all its children
if ($_category->getId() == $categoryId)
{
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$_catChildrens = $_category->getAllChildren();
foreach(explode(',',$_catChildrens) as $index=>$child)
{
$cat = Mage::getModel('catalog/category')->load($child);
if($cat->getLevel() == 3 && $cat->getIsActive())
{
$isParent = ($cat->hasChildren()) ? 'parent' : '';
$treeHtml .= '<li class="level1 nav'.$cat->getLevel().' '.$isParent.'">'.
'<a href="'.$cat->getUrl().'">'.
$cat->getName().
'</a>';
if($cat->hasChildren())
{
$treeHtml .= '<div class="sub-menu-wrap"><ul class="level1">';
foreach($cat->getChildrenCategories() as $indx=>$_subcategory)
{
if($_subcategory->getIsActive())
{
$cat4 = Mage::getModel('catalog/category')->load($indx);
$treeHtml .= '<li class="level2 nav'.$cat4->getLevel().'">'.
'<a href="'.$cat4->getUrl().'">'.
$cat4->getName().
'</a></li>';
}
}
$treeHtml .= '</ul></div>';
}
$treeHtml .= '</li>';
}
}
return $treeHtml;
}
}
}
}

Codeigniter nested foreach in slideshow?

I ask this https://stackoverflow.com/a/14277726/1670630 on other post but my problem still exist.
In codeigniter 2.1 I'm trying to display channels by category. So if i have a category called Film, i should see a list of Channels within Film. I tried a nested foreach loop to accomplish this but can't seem to get it to work in the slidshow and limit by number of row.
My model:
<?php
class Pages_model extends CI_Model {
function get_channels_by_categ_tv()
{
$this->db->select('categories.category_name, channels.channel_name');
$this->db->from('type_categ');
$this->db->join('categories', 'categories.category_id = type_categ.category_id');
$this->db->join('channels', 'channels.channel_id = type_categ.channel_id');
$this->db->order_by('categories.category_id');
//$this->db->group_by(array('categories.category_id'));
$query = $this->db->get();
if($query->num_rows() == 0)
{
#no channels
return false;
}
return $query->result_array();
}
}
I have this in the view:
<ul class="slides">
<li>
<?php $cat_shown = ''; ?>
<div class="programe-tv_link">
<?php $cat_show = ''; $cnl_show = '';?>
<?php foreach ($category_chaneels as $category): ?>
<?php
if ($cat_show != $category['category_name']) {
$cat_show = $category['category_name'];
echo '<p>' . $cat_show . '</p>';
}
$cnl_show = $category['channel_name'];
echo '<dd> >>' . $cnl_show . '</dd> ';
?>
<?php endforeach; ?>
</div>
</li>
<li>
<div class="programe-tv_link">
<p>Arte</p>
<dd> >> Acasa</dd>
<dd> >> Antena 1</dd>
<dd> >> Pro TV</dd>
</div>
<div class="programe-tv_link">
<p>Music Box</p>
<dd> >> Acasa</dd>
<dd> >> Antena 1</dd>
<dd> >> Pro TV</dd>
<dd> >> TLC</dd>
</div>
</li>
</ul>
I atache image with ilustration,
sorry for my english and if you don't understund me please write here. THX in advance.
My finale code is this.
<div id="programe-tv-slide" class="flexslider">
<strong>Programe TV</strong>
<div class="redLine"></div>
<?php $cat_cnl = array();
$list = array();
$i=1;
foreach ($category_chaneels as $option) {
$catname = $option['category_name'];
$chlname = $option['channel_name'];
$cat_cnl[$catname][$i] = $chlname;
$list[$i] = $catname;
$i++;
};
?>
<?php
$rows = array_chunk($cat_cnl, 4, TRUE);
foreach ($rows as $row) { //var_dump($rows);
?>
<ul class="slides">
<?php
echo ('<li>');
foreach ($row as $category => $channels) {
echo '<div class="programe-tv_link">';
echo '<p>' . $category . '</p>';
foreach ($channels as $channel) {
echo '<dd>' . $channel . '</dd> ';
};
echo '</div>';
};
echo ('</li>');
?>
</ul>
<?php }; ?>
</div>

I need to get a list of sibling categories in magento 1.7

So far I think i am working at something like this
<?php
$parentId = $_category->getParentId();
$cats = Mage::getModel('catalog/category')->load($parentId)->getChildred();
$catIds = explode(',',$cats);
?>
<ul>
<?php foreach($catIds as $catId): ?>
<li>
<?php
$category=Mage::getModel('catalog/category')->load($catId)
echo $category->getName();
?>
</li>
<?php endforeach; ?>
</ul>
I am trying to have lateral movement in subcategories without having to go up a layer.
Let me know if that made sense.
The below code will helps you to load 2nd level (sub)category. you can set the $_rootCatId as dynamic also by Mage::app()->getStore()->getRootCategoryId();.
$_rootCatId = 2;//Root Category
$_rootCategory = Mage::getModel('catalog/category')->load($_rootCatId);
$_catName = $_rootCategory->getName();
if($_rootCategory->hasChildren())
{
$_collection = Mage::getResourceModel('catalog/category_collection')
->addAttributeToFilter('is_active', 1)
->addAttributeToSort('position', 'asc')
->joinUrlRewrite()
->addIdFilter($_rootCategory->getChildren())
->load();
foreach($_collection AS $_sub)
{
$_subCat = Mage::getModel('catalog/category')->load($_sub->getId());
if($_subCat->hasChildren())
{
echo '<li class="leve10 nav-'. $_subCat->getId() .'">';
echo '<a id="subCatLink">';
echo '<span>'. $this->htmlEscape($_subCat->getName()) .'</span>
</a>
</li>';
echo '<ul id="subCatUl" class="no-display" style="padding:0px 13px;">';
$__collection = Mage::getResourceModel('catalog/category_collection')
->addAttributeToFilter('is_active', 1)
->addAttributeToSort('position', 'asc')
->joinUrlRewrite()
->addIdFilter($_subCat->getChildren())
->load();
foreach($__collection AS $__sub)
{
$__subCat = Mage::getModel('catalog/category')->load($__sub->getId());
echo '<li class="leve20 nav-'. $__subCat->getId() .'">
<a href="'. $this->getCategoryUrl($__subCat) .'">
<span>'. $this->htmlEscape($__subCat->getName()) .'</span>
</a>
</li>';
}
echo '</ul>';
}
else
{
echo '<li class="leve10 nav-'. $_subCat->getId() .'">
<a href="'. $this->getCategoryUrl($_subCat) .'">
<span>'. $this->htmlEscape($_subCat->getName()) .'</span>
</a>
</li>';
}
}
}
else
echo 'No Categories Found...';
Assuming that your $_category is a valid instance of Mage_Catalog_Model_Category:
<?php $_siblings = $_category->getParentCategory()->getChildrenCategories(); ?>
<ul>
<?php foreach($_siblings as $_sibling): ?>
<li>
<?php echo $_sibling->getName(); ?>
</li>
<?php endforeach; ?>
</ul>

Codeigniter multiple views for nested tab setup

I am struggling with nested tab markup generated via Codeigniter model calls and would welcome any insightful comments. The difficulty is that the markup generated has unwanted repetitions of blocks of project data. The use of multiple views which are not straightforwardly inter-connected is probably where the problems lie.
Here's the controller:
function projects() {
$this->load->model('msm_projects');
$data['cats']=$this->msm_projects->catid()->result_array();
$this->load->view('vup_projects', $data);
foreach ( $data['cats'] as $item )
{
$data2['projects']=$this->msm_projects->catproj($item['catid'])->result_array();
$this->load->view('vup_projects2', $data2);
}
}
The model:
function catid() {
return $this->db->query("SELECT DISTINCT catid, cat FROM category INNER JOIN projects ON catid = projcat WHERE projpub=1 ORDER BY catid ASC");
}
function catproj($catid) {
return $this->db->query("SELECT catid, cat, projcat, projid, projtit FROM projects INNER JOIN category ON projcat = catid WHERE projcat = $catid AND projpub=1 ORDER BY catid ASC");
}
Here are the views which are in two parts. I suspect this is where it's all going wrong. There's an imperfect join between the two views which I am having a hard time thinking about.
view 1 called 'vup_projects'
<div id="wrapper">
<div class="yui3-g">
<div class="yui3-u-1"><div id="topbloc"><img src="http://localhost/getop/base-images/topbloc.gif" width="800" height="50" align="middle"></div></div>
<div class="yui3-u-1">
<div id="navbloc">
<div id="linx">
<ul >
<li id="about"><?php echo anchor('cu_tya/about', 'about'); ?></li>
<li id="ourwork"><?php echo anchor('cu_projects/projects', 'projects'); ?></li>
<li id="contact"><?php echo anchor('cu_tya/contact', 'contact'); ?></li>
<li id="member"><?php echo anchor('cu_sites/pager', 'your page'); ?></li>
</ul>
</div>
</div>
</div>
<div class="yui3-u-1">
<div id="container">
<ul>
<?php
foreach ( $cats as $item ) // top tabs
{
echo '<li><a href=#fragment-'.$item['catid'].'><span>'.$item['cat'].'</span></a></li>';
}
?>
</ul>
And the second view vup_projects2
<?php foreach ( $cats as $item ) { ?> <!-- main divs -->
<div id="fragment-<?php echo $item['catid'];?>">
<ul>
<?php foreach ( $projects as $project )
{ ?>
<li>
<span><?php echo $project['projtit'];?></span></li>
<?php } ?>
</ul>
<?php foreach ( $projects as $project )
{ ?>
<div id="fragment-<?php echo $project['projid'];?>a" >
<?php echo $project['projtit'].' hooray';?>
</div>
<?php } ?>
</div>
<?php } ?>
</div> <!-- container -->
</div> <!-- YUI-UNIT-1-->
</div> <!-- YUI-GRID -->
</div> <!-- wrapper -->
foreach ( $data['cats'] as $item )
{
$data2['projects']=$this->msm_projects->catproj($item['catid'])->result_array();
$this->load->view('vup_projects2', $data2);
}
is your problem, you're looping the views for every item in $data['cats']... you're also doing a query for every $item. You should do one query and then loop through the results accordingly. But to fix your problem, try this:
foreach ( $data['cats'] as $item )
{
$data2['projects'][$item['catid']] = $this->msm_projects->catproj($item['catid'])
->result_array();
}
$this->load->view('vup_projects2', $data2);
then change your second view to
<?php foreach ( $cats as $item ) { ?> <!-- main divs -->
<div id="fragment-<?php echo $item['catid'];?>">
<ul>
<?php foreach ( $projects[$item['catid']] as $project )
{ ?>
<li>
<span><?php echo $project['projtit'];?></span></li>
<?php } ?>
</ul>
<?php foreach ( $projects[$item['cat_id']] as $project )
{ ?>
<div id="fragment-<?php echo $project['projid'];?>a" >
<?php echo $project['projtit'].' hooray';?>
</div>
<?php } ?>
</div> <!-- container -->
</div> <!-- YUI-UNIT-1-->
</div> <!-- YUI-GRID -->
</div> <!-- wrapper -->
So I took a closer look at what your trying to accomplish and I think I consolidated it into a single query and a single view. Maybe this will help
Controller:
class Projects extends CI_Controller {
function __construct(){
parent::__construct();
}
function projects() {
$cats = array(); // Unique cateogires
$projects = array(); // Projects that will go underneath
$this->load->model('msm_projects');
$query = $this->msm_projects->get_all();
// Make sure there are results
if ($query !== FALSE)
{
// Loop through once to find distinct categories for tabs
foreach ($query as $k => $v)
{
if ( ! array_key_exists($v['catid'], $tabs))
{
$tabs[$v['catid']] = $v['cat'];
}
}
// Loop through all of the results and group the items
// into arrays by their categories
foreach ($query as $k => $v)
{
$projects[$v['catid']][] = $v;
}
$data = array(
'cats' => $cats,
'projects' => $projects
);
$this->load->view('main', $data);
}
else
{
echo 'No results';
}
}
}
Model:
class Msm_projects extends CI_Model {
/* Returns everything you need */
function get_all()
{
$q = $this->db->select('c.catid, c.cat, p.projcat, p.projid, p.projtit')
->join('projects as p', 'c.catid = p.projcat', 'INNER')
->where('projpub = 1')
->order_by('c.catid')
->get('category as c');
if ($q->num_rows > 0)
{
return $q->result_array();
}
else
{
return FALSE;
}
}
}
View:
<div id="wrapper">
<div class="yui3-g">
<div class="yui3-u-1">
<div id="topbloc">
<img src="<?=base_url() /* Good not to hardcode url's if you can avoid it */;?>getop/base-images/topbloc.gif" width="800" height="50" align="middle" />
</div>
</div>
<div class="yui3-u-1">
<div id="navbloc">
<div id="linx">
<ul >
<li id="about"><?php echo anchor('cu_tya/about', 'about'); ?></li>
<li id="ourwork"><?php echo anchor('cu_projects/projects', 'projects'); ?></li>
<li id="contact"><?php echo anchor('cu_tya/contact', 'contact'); ?></li>
<li id="member"><?php echo anchor('cu_sites/pager', 'your page'); ?></li>
</ul>
</div>
</div>
</div>
<div class="yui3-u-1">
<div id="container">
<ul>
<?php foreach($cats as $id => $cat){ ?>
<li><span><?=$cat['cat'];?></span></li>
<?php } ?>
</ul>
<?php foreach ($cats as $id => $cat ) { ?> <!-- main divs -->
<div id="fragment-<?php echo $id;?>">
<ul>
<?php foreach($projects[$id] as $project){ ?>
<li>
<span><?php echo $project['projtit'];?></span>
</li>
<?php } ?>
</ul>
<?php foreach ($projects[$id] as $project) { ?>
<div id="fragment-<?php echo $project['projid'];?>a" >
<?php echo $project['projtit'].' hooray';?>
</div>
<?php } ?>
</div>
<?php } ?>
There are a lot of tricks to learn about optimizing the MVC process in CI, a lot of which I wish I learned earlier. Hopefully this helps some, let me know if you have questions. As for the pagination, try doing something similar to what i did in the foreach loop to get the main categories, and then subsequently pulling the pages out of the result array which are == to the category you're looking for.

Resources