CodeIgniter Set Form Validation Redirect URL - codeigniter

When the form doesn't get run because some of the fields are missing the form validator redirects back to current controller/method by default. This means that if I've set a route for 'signup' that routes to auth/register I want it to redirect back to the route path not the actual controller path.
Any suggestions?
function register() {
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required|xss_clean');
$this->form_validation->set_rules('description', 'Description', 'required|xss_clean');
$this->form_validation->set_rules('contact', 'Contact', 'required|xss_clean');
$this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required');
if ($this->form_validation->run() == true) {
// Do some stuff here
} else {
$data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
$data['name'] = array('name' => 'name',
'id' => 'name',
'type' => 'text',
'value' => $this->form_validation->set_value('name'),
);
$data['description'] = array('name' => 'description',
'id' => 'description',
'type' => 'textarea',
'value' => $this->form_validation->set_value('description'),
'class' => 'form-textarea',
);
$data['email'] = array('name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email'),
);
$data['contact'] = array('name' => 'contact',
'id' => 'contact',
'type' => 'text',
'value' => $this->form_validation->set_value('contact'),
);
$data['password'] = array('name' => 'password',
'id' => 'password',
'type' => 'password',
'value' => $this->form_validation->set_value('password'),
);
$data['password_confirm'] = array('name' => 'password_confirm',
'id' => 'password_confirm',
'type' => 'password',
'value' => $this->form_validation->set_value('password_confirm'),
);
$this->load->view('organisations/create', $data);
}
}

I would set the default behavior to what you want if the form is not submitted or if there are validation errors and then redirect if the user if the form is successfully processed.
i.e.
function register() {
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'Name', 'required|xss_clean');
$this->form_validation->set_rules('description', 'Description', 'required|xss_clean');
$this->form_validation->set_rules('contact', 'Contact', 'required|xss_clean');
$this->form_validation->set_rules('email', 'Email Address', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required');
if ($this->form_validation->run()) {
// Do some stuff here to process the form
// Maybe set the success flash message
// Then redirect
redirect('organizations/login');
} else {
$data['message'] = (validation_errors() ? validation_errors() : ($this->ion_auth->errors() ? $this->ion_auth->errors() : $this->session->flashdata('message')));
$data['name'] = array('name' => 'name',
'id' => 'name',
'type' => 'text',
'value' => $this->form_validation->set_value('name'),
);
$data['description'] = array('name' => 'description',
'id' => 'description',
'type' => 'textarea',
'value' => $this->form_validation->set_value('description'),
'class' => 'form-textarea',
);
$data['email'] = array('name' => 'email',
'id' => 'email',
'type' => 'text',
'value' => $this->form_validation->set_value('email'),
);
$data['contact'] = array('name' => 'contact',
'id' => 'contact',
'type' => 'text',
'value' => $this->form_validation->set_value('contact'),
);
$data['password'] = array('name' => 'password',
'id' => 'password',
'type' => 'password',
'value' => $this->form_validation->set_value('password'),
);
$data['password_confirm'] = array('name' => 'password_confirm',
'id' => 'password_confirm',
'type' => 'password',
'value' => $this->form_validation->set_value('password_confirm'),
);
}
$this->load->view('organisations/create', $data);
}
This may require you to change the way you structure some things now, but I've found this to be the easiest way to handle this situation.

Related

Magento - Adminhtml Trying to search in the product grid by custom column

I am using Magento 1.9.2 and i am rewriting the products grid table.
I have done a copy from the original Grid.php and created this:
/app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php and here is what it contains:
<?php
class Mage_Adminhtml_Block_Catalog_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('productGrid');
$this->setDefaultSort('entity_id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
$this->setVarNameFilter('product_filter');
}
protected function _getStore()
{
$storeId = (int) $this->getRequest()->getParam('store', 0);
return Mage::app()->getStore($storeId);
}
protected function _prepareCollection()
{
$store = $this->_getStore();
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('sku')
->addAttributeToSelect('name')
->addAttributeToSelect('attribute_set_id')
->addAttributeToSelect('type_id');
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
$collection->joinField('qty',
'cataloginventory/stock_item',
'qty',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left');
}
if ($store->getId()) {
//$collection->setStoreId($store->getId());
$adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
$collection->addStoreFilter($store);
$collection->joinAttribute(
'name',
'catalog_product/name',
'entity_id',
null,
'inner',
$adminStore
);
$collection->joinAttribute(
'custom_name',
'catalog_product/name',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'status',
'catalog_product/status',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'visibility',
'catalog_product/visibility',
'entity_id',
null,
'inner',
$store->getId()
);
$collection->joinAttribute(
'price',
'catalog_product/price',
'entity_id',
null,
'left',
$store->getId()
);
}
else {
$collection->addAttributeToSelect('price');
$collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
$collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
}
$this->setCollection($collection);
parent::_prepareCollection();
$this->getCollection()->addWebsiteNamesToResult();
return $this;
}
protected function _addColumnFilterToCollection($column)
{
if ($this->getCollection()) {
if ($column->getId() == 'websites') {
$this->getCollection()->joinField('websites',
'catalog/product_website',
'website_id',
'product_id=entity_id',
null,
'left');
}
}
return parent::_addColumnFilterToCollection($column);
}
protected function _prepareColumns()
{
$this->addColumn('entity_id',
array(
'header'=> Mage::helper('catalog')->__('ID'),
'width' => '50px',
'type' => 'number',
'index' => 'entity_id',
));
$this->addColumn('name',
array(
'header'=> Mage::helper('catalog')->__('Name'),
'index' => 'name',
));
$store = $this->_getStore();
if ($store->getId()) {
$this->addColumn('custom_name',
array(
'header'=> Mage::helper('catalog')->__('Name in %s', $store->getName()),
'index' => 'custom_name',
));
}
$this->addColumn('type',
array(
'header'=> Mage::helper('catalog')->__('Type'),
'width' => '60px',
'index' => 'type_id',
'type' => 'options',
'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
));
$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
->load()
->toOptionHash();
$this->addColumn('set_name',
array(
'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
'width' => '100px',
'index' => 'attribute_set_id',
'type' => 'options',
'options' => $sets,
));
$this->addColumn('sku',
array(
'header'=> Mage::helper('catalog')->__('SKU'),
'width' => '80px',
'index' => 'sku',
));
$this->addColumn('number',
array(
'header'=> Mage::helper('catalog')->__('Поръчка №'),
'width' => '50px',
'index' => 'entity_id',
'renderer' => 'Mage_Adminhtml_Block_Catalog_Product_Renderer',
));
$store = $this->_getStore();
$this->addColumn('price',
array(
'header'=> Mage::helper('catalog')->__('Price'),
'type' => 'price',
'currency_code' => $store->getBaseCurrency()->getCode(),
'index' => 'price',
));
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
$this->addColumn('qty',
array(
'header'=> Mage::helper('catalog')->__('Qty'),
'width' => '100px',
'type' => 'number',
'index' => 'qty',
));
}
$this->addColumn('visibility',
array(
'header'=> Mage::helper('catalog')->__('Visibility'),
'width' => '70px',
'index' => 'visibility',
'type' => 'options',
'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
));
$this->addColumn('status',
array(
'header'=> Mage::helper('catalog')->__('Status'),
'width' => '70px',
'index' => 'status',
'type' => 'options',
'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
));
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('websites',
array(
'header'=> Mage::helper('catalog')->__('Websites'),
'width' => '100px',
'sortable' => false,
'index' => 'websites',
'type' => 'options',
'options' => Mage::getModel('core/website')->getCollection()->toOptionHash(),
));
}
$this->addColumn('action',
array(
'header' => Mage::helper('catalog')->__('Action'),
'width' => '50px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('catalog')->__('Edit'),
'url' => array(
'base'=>'*/*/edit',
'params'=>array('store'=>$this->getRequest()->getParam('store'))
),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
));
if (Mage::helper('catalog')->isModuleEnabled('Mage_Rss')) {
$this->addRssList('rss/catalog/notifystock', Mage::helper('catalog')->__('Notify Low Stock RSS'));
}
return parent::_prepareColumns();
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('entity_id');
$this->getMassactionBlock()->setFormFieldName('product');
$this->getMassactionBlock()->addItem('delete', array(
'label'=> Mage::helper('catalog')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('catalog')->__('Are you sure?')
));
$statuses = Mage::getSingleton('catalog/product_status')->getOptionArray();
array_unshift($statuses, array('label'=>'', 'value'=>''));
$this->getMassactionBlock()->addItem('status', array(
'label'=> Mage::helper('catalog')->__('Change status'),
'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'status',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('catalog')->__('Status'),
'values' => $statuses
)
)
));
if (Mage::getSingleton('admin/session')->isAllowed('catalog/update_attributes')){
$this->getMassactionBlock()->addItem('attributes', array(
'label' => Mage::helper('catalog')->__('Update Attributes'),
'url' => $this->getUrl('*/catalog_product_action_attribute/edit', array('_current'=>true))
));
}
Mage::dispatchEvent('adminhtml_catalog_product_grid_prepare_massaction', array('block' => $this));
return $this;
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array(
'store'=>$this->getRequest()->getParam('store'),
'id'=>$row->getId())
);
}
}
The custom code i've added in the Grid.php is this:
$this->addColumn('number',
array(
'header'=> Mage::helper('catalog')->__('Поръчка №'),
'width' => '50px',
'index' => 'entity_id',
'renderer' => 'Mage_Adminhtml_Block_Catalog_Product_Renderer',
));
I have created and rendered also, i saw this in another answer:
<?PHP
class Mage_Adminhtml_Block_Catalog_Product_Renderer extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$productId = $row->getData($this->getColumn()->getIndex());
$orders = array();
$collection = Mage::getResourceModel('sales/order_item_collection')
->addAttributeToFilter('product_id', array('eq' => $productId))
->load();
foreach($collection as $orderItem) {
$orders[$orderItem->getOrder()->getIncrementId()] = $orderItem->getOrder();
}
$first_key = key($orders);
return $first_key;
}
}
I have added the additional column so i can display in every row in which order ID the product is purchased. I have no problems. Everything is correct, but the problem comes when i try to search with this custom column.
The order ID is displayed correctly in the column but can not be searched by order ID.
Where is my mistake, why it is not working and how can i fix it?
Thanks in advance!
You are unable to search your custom_column in grid because you have just used renderer which returns order_id in run time and prepare your columns. That's it. What magento grid search do, it filters the loaded collection with "search text".
For example:- you make a search for order_id = 10000901, your search result returns null because order_id is not present in collection.
So you should join sales_flat_order & sales_flat_order_item with your product table in order to get increment_id in collection. Then sorting & searching both will work perfectly.
Please add this code
$collection->getSelect()->joinLeft(
array('order_item'=>'sales_flat_order_item'),
'e.entity_id = order_item.product_id',
array('order_item.product_id','order_item.order_id')
);
$collection->getSelect()->joinLeft(
array('order'=>'sales_flat_order'),
'order_item.order_id = `order`.entity_id',
array('order.increment_id')
);
$collection->getSelect()->group('e.entity_id');
before $this->setCollection($collection); in method _prepareCollection() of your /app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php
and
update column code as below
$this->addColumn('increment_id',
array(
'header'=> Mage::helper('catalog')->__('Order Id'),
'width' => '100px',
'type' => 'number',
'index' => 'increment_id',
));

Zf2 entity create a custom filters

public function getInputFilter($em){
if (!$this->inputFilter) {
$inputFilter = new InputFilter();
$inputFilter->add(array(
'name' => 'fullName',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
array('name' => 'SpecialChar')
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 5,
'max' => 100,
),
),
),
));
$inputFilter->add(array(
'name' => 'password',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
));
$inputFilter->add(array(
'name' => 'email',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'EmailAddress',
),
array(
'name' => 'User\Validator\NoEntityExists',
'options'=>array(
'entityManager' =>$em,
'class' => 'User\Entity\User',
'property' => 'email',
'exclude' => array(
array('property' => 'id', 'value' => $this->getId())
)
)
)
),
));
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}
I want to add a new function in entity called "Special Char" in all input fields, so how does one create a custom filter in a doctrine entity.
I want to add validation to avoid special char in entity because I need to use this in n no of places.
How do I implement this?
From Zend documentation:
namespace Application\Filter;
use Zend\Filter\FilterInterface;
class MyFilter implements FilterInterface
{
public function filter($value)
{
// perform some transformation upon $value to arrive on $valueFiltered
return $valueFiltered;
}
}
Then you should be able to do:
$inputFilter->add(array(
'name' => 'fullName',
'required' => true,
'filters' => array(
array('name' => 'Application\Filter\MyFilter')
…

How to get Manufacturer dropdown in custom module edit form?

I want to add images for each brand, for that i have created a module. in module's edit form i want a manufacturer dropdown list so i can assign image to the particular manufacturer/brand.
its my code for the edit form location:
app/code/local/Root/Brand/Block/Adminhtml/Brand/Edit/Tab/form.php
$fieldset->addField('title', 'select', array(
'name' => 'title',
'label' => 'Brand',
'values' => Mage::getUrl('catalogsearch/advanced/result', array(
'brand' => $option['value']
))
));
$fieldset->addField('filename', 'image', array(
'label' => Mage::helper('brand')->__('Brand Image') ,
'required' => false,
'name' => 'filename',
'note' => '(*.jpg, *.png, *.gif)'
));
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'manufacturer');
//here, "brandname" is the attribute_code
$allOptions = $attribute->getSource()->getAllOptions(true, true);
$fieldset->addField('title', 'select', array(
'label' => Mage::helper('brand')->__('Brand Name'),
'name' => 'title',
'values' => $allOptions
));

In codeigniter redirect to paypal after order placed ,submitting form from controller

I'm very new to codeigniter.my question is after submitting billing and shipping address how to i redirect to paypal.I mean is there any way to redirect/form submission from controller.Below is my place order function in controller
function place_order()
{
if ($this->input->server('REQUEST_METHOD') === 'POST')
{
$this->form_validation->set_rules('bill_first_name', 'First Name', 'trim|required');
$this->form_validation->set_rules('bill_last_name', 'Last Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('address', 'Address', 'trim|required');
$this->form_validation->set_rules('phone', 'Phone', 'trim|required');
if ($this->form_validation->run())
{
$data_to_store = array(
'bill_first_name' => $this->input->post('bill_first_name'),
'bill_last_name' => $this->input->post('bill_last_name'),
'email' => $this->input->post('email'),
'address' => $this->input->post('address'),
'phone' => $this->input->post('phone'),
'country' => $this->input->post('country'),
'city' => $this->input->post('city'),
'zip' => $this->input->post('zip'),
'user_id' => $this->session->userdata('sess_user_id'),
'session_id' => $this->session->userdata('session_id'),
'create_date' => date('Y-m-d H:i:s')
);
$customer=$this->checkout_model->add_user('tbl_customer',$data_to_store);
if($customer){
$data = array(
'customer_id' => $customer,
'user_id' => $this->session->userdata('sess_user_id'),
'session_id' => $this->session->userdata('session_id'),
'create_date' => date('Y-m-d H:i:s')
);
$order=$this->checkout_model->add_user('tbl_order',$data);
if($order)
{
if ($cart = $this->cart->contents()):
foreach ($cart as $item):
$order_detail = array(
'order_id' => $order,
'product_id' => $item['id'],
'qty' => $item['qty'],
'product_price' => $item['price'],
'sub_total' => $item['qty'] * $item['price']
);
$cust_id = $this->checkout_model->add_user('tbl_order_details',$order_detail);
endforeach;
endif;
}
$this->cart->destroy();
}
paypallllllllllllllllllllllll
}
}
On the bottom of this page of the manual, you can find the redirect()-function (using the URL-helper).
--- EDIT ---
Maybe something like this (see this answer):
$query_data = array(
'business' => 'your-paypal-email-address',
'cmd' => '_xclick',
'item_name' => 'Order #' . $order,
'amount' => '100.00', // update with your total price
'shipping' => '10.00'
);
header('Location: https://www.paypal.com/cgi-bin/websrc/?' . http_build_query($query_data));

Codeigniter: Display multiple images from database for

I'm running a real estate website. I'm trying to list all images in the database for a particular listing on their respective page. I have the following code but it just repeats the same default image instead of showing all images for that listing.
Model:
public function getDetails($listing_id)
{
$this->db->select(
'listings.listing_id AS id,
listings.account_id AS account_id,
listings.nbrhood_id AS nbrhood_id,
listings.price AS price,
listings.convertible AS convertible,
listings.available AS available,
images.file_name AS file_name,
listings.sqft AS sqft,
listings.db_tag AS db_tag,
listings.web_id AS web_id,
listings.description AS description,
bedrooms.beds_num AS beds_val,
bedrooms.beds_name AS beds_text,
bathrooms.baths_num AS baths_val,
bathrooms.baths_name AS baths_text,
nbrhoods.nbrhood_name AS nbrhood,
nbrhoods.image AS nbrhood_image,
types_listings.type_name AS type,
pets.pet_name AS pets'
);
$this->db->join('images', 'images.image_id = listings.image_id', 'left');
$this->db->join('bedrooms', 'bedrooms.beds_id = listings.beds_id');
$this->db->join('bathrooms', 'bathrooms.baths_id = listings.baths_id');
$this->db->join('nbrhoods', 'nbrhoods.nbrhood_id = listings.nbrhood_id');
$this->db->join('types_listings', 'types_listings.type_id = listings.type_id');
$this->db->join('pets', 'pets.pet_id = listings.pet_id');
$this->db->where('listings.listing_id', $listing_id);
$this->db->limit(1);
return $this->db->get($this->table_name)->row();
}
PHP:
<?php foreach ($listing AS $listing_id): ?>
<li data-image-id="<?=$image -> image_id ?>" class="uploaded-image" id="image_<?=$image -> image_id ?>">
<div class="sortableimagewrapper">
<!-- <span class="label label-inverse image-name"> </span> -->
<img src="<?=images_url('110x68/' . $listing -> file_name) ?>" alt="" width="110px" height="68px" class="img-polaroid" />
</div>
</li>
<?php endforeach; ?>
class Listing_Model extends CW_Model {
protected $table_name = 'listings';
protected $order_by = 'listing_id';
protected $primary_key = 'listing_id';
protected $display_val = '';
public $defaults = array(
'status_id' => 1
);
public $qualifiers = array('listing_id', 'account_id', 'status_id', 'image_id', 'file_name', 'featured', 'feature_id', 'deal_id', 'nbrhood_id', 'beds_id', 'baths_id', 'pet_id', 'type_id', 'owner_id', 'web_id', 'price', 'convertible', 'available', 'sqft', 'address', 'unit', 'zip', 'description', 'notes');
public $rules = array(
'new' => array(
'listing_id' => array(
'field' => 'listing_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'account_id' => array(
'field' => 'account_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'status_id' => array(
'field' => 'status_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'image_id' => array(
'field' => 'image_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'file_name' => array(
'field' => 'file_name',
'label' => '',
'rules' => 'trim|xss_clean'
),
'featured' => array(
'field' => 'featured',
'label' => '',
'rules' => 'trim|xss_clean'
),
'feature_id' => array(
'field' => 'feature_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'deal_id' => array(
'field' => 'deal_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'nbrhood_id' => array(
'field' => 'nbrhood_id',
'label' => 'Neighborhood',
'rules' => 'trim|required|xss_clean'
),
'beds_id' => array(
'field' => 'beds_id',
'label' => 'Bedrooms',
'rules' => 'trim|required|xss_clean'
),
'baths_id' => array(
'field' => 'baths_id',
'label' => 'Bathrooms',
'rules' => 'trim|required|xss_clean'
),
'pet_id' => array(
'field' => 'pet_id',
'label' => 'Pets',
'rules' => 'trim|required|xss_clean'
),
'type_id' => array(
'field' => 'type_id',
'label' => 'Listing Type',
'rules' => 'trim|required|xss_clean'
),
'owner_id' => array(
'field' => 'owner_id',
'label' => 'Owner/Landlord',
'rules' => 'trim|required|xss_clean'
),
'web_id' => array(
'field' => 'web_id',
'label' => 'Web ID',
'rules' => 'trim|alpha_dash|xss_clean'
),
'price' => array(
'field' => 'price',
'label' => 'Price',
'rules' => 'trim|required|min_length[3]|integer|xss_clean'
),
'convertible' => array(
'field' => 'convertible',
'label' => 'Convertible',
'rules' => 'trim|is_natural|xss_clean'
),
'dateAvailable' => array(
'field' => 'dateAvailable',
'label' => '',
'rules' => 'trim|xss_clean'
),
'available' => array(
'field' => 'available',
'label' => 'Date Available',
'rules' => 'trim|required|xss_clean'
),
'sqft' => array(
'field' => 'sqft',
'label' => 'Square Feet',
'rules' => 'trim|min_length[3]|integer|xss_clean'
),
'address' => array(
'field' => 'address',
'label' => 'Street Address',
'rules' => 'trim|required|min_length[12]|xss_clean'
),
'unit' => array(
'field' => 'unit',
'label' => 'Unit Number',
'rules' => 'trim|required|max_length[5]|alpha_dash|xss_clean'
),
'zip' => array(
'field' => 'zip',
'label' => 'Zip Code',
'rules' => 'trim|required|exact_length[5]|integer|xss_clean'
),
'description' => array(
'field' => 'description',
'label' => 'Description',
'rules' => 'trim|required|min_length[175]|xss_clean'
),
'notes' => array(
'field' => 'notes',
'label' => 'Notes',
'rules' => 'trim|xss_clean'
),
'amenity_ids[unit][]' => array(
'field' => 'amenity_ids[unit][]',
'label' => 'Unit Amenities',
'rules' => 'trim|xss_clean'
),
'amenity_ids[property][]' => array(
'field' => 'amenity_ids[property][]',
'label' => 'Property Amenities',
'rules' => 'trim|xss_clean'
),
'image_ids[]' => array(
'field' => 'image_ids[]',
'label' => '',
'rules' => 'trim|xss_clean'
)
),
'edit' => array(
'listing_id' => array(
'field' => 'listing_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'account_id' => array(
'field' => 'account_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'status_id' => array(
'field' => 'status_id',
'label' => '',
'rules' => 'trim|required|xss_clean'
),
'image_id' => array(
'field' => 'image_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'file_name' => array(
'field' => 'file_name',
'label' => '',
'rules' => 'trim|xss_clean'
),
'featured' => array(
'field' => 'featured',
'label' => '',
'rules' => 'trim|xss_clean'
),
'feature_id' => array(
'field' => 'feature_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'deal_id' => array(
'field' => 'deal_id',
'label' => '',
'rules' => 'trim|xss_clean'
),
'nbrhood_id' => array(
'field' => 'nbrhood_id',
'label' => 'Neighborhood',
'rules' => 'trim|required|xss_clean'
),
'price' => array(
'field' => 'price',
'label' => 'Price',
'rules' => 'trim|required|min_length[3]|integer|xss_clean'
),
'beds_id' => array(
'field' => 'beds_id',
'label' => 'Bedrooms',
'rules' => 'trim|required|xss_clean'
),
'convertible' => array(
'field' => 'convertible',
'label' => 'Convertible',
'rules' => 'trim|is_natural|xss_clean'
),
'baths_id' => array(
'field' => 'baths_id',
'label' => 'Bathrooms',
'rules' => 'trim|required|xss_clean'
),
'dateAvailable' => array(
'field' => 'dateAvailable',
'label' => '',
'rules' => 'trim|xss_clean'
),
'available' => array(
'field' => 'available',
'label' => 'Date Available',
'rules' => 'trim|required|xss_clean'
),
'pet_id' => array(
'field' => 'pet_id',
'label' => 'Pets',
'rules' => 'trim|required|xss_clean'
),
'sqft' => array(
'field' => 'sqft',
'label' => 'Square Feet',
'rules' => 'trim|min_length[3]|integer|xss_clean'
),
'type_id' => array(
'field' => 'type_id',
'label' => 'Listing Type',
'rules' => 'trim|required|xss_clean'
),
'description' => array(
'field' => 'description',
'label' => 'Description',
'rules' => 'trim|required|min_length[175]|xss_clean'
),
'amenity_ids[unit][]' => array(
'field' => 'amenity_ids[unit][]',
'label' => 'Unit Amenities',
'rules' => 'trim|xss_clean'
),
'amenity_ids[property][]' => array(
'field' => 'amenity_ids[property][]',
'label' => 'Property Amenities',
'rules' => 'trim|xss_clean'
),
'owner_id' => array(
'field' => 'owner_id',
'label' => 'Owner/Landlord',
'rules' => 'trim|required|xss_clean'
),
'address' => array(
'field' => 'address',
'label' => 'Street Address',
'rules' => 'trim|required|min_length[12]|xss_clean'
),
'unit' => array(
'field' => 'unit',
'label' => 'Unit Number',
'rules' => 'trim|required|max_length[5]|alpha_dash|xss_clean'
),
'zip' => array(
'field' => 'zip',
'label' => 'Zip Code',
'rules' => 'trim|required|exact_length[5]|integer|xss_clean'
),
'notes' => array(
'field' => 'notes',
'label' => 'Notes',
'rules' => 'trim|xss_clean'
),
'image_ids[]' => array(
'field' => 'image_ids[]',
'label' => '',
'rules' => 'trim|xss_clean'
),
'web_id' => array(
'field' => 'web_id',
'label' => 'Web ID',
'rules' => 'trim|alpha_dash|xss_clean'
)
)
);
public function __construct() {
parent::__construct();
}
public function getNew() {
// Remember everytime you add a field you have to add it to form validation...
$listing = new stdClass();
$listing->listing_id = $this->_get_identifier();
$listing->account_id = $this->session->userdata('account_id');
$listing->status_id = 0;
$listing->feature_id = '';
$listing->image_id = 0;
$listing->nbrhood_id = ''; // Dropdown
$listing->beds_id = ''; // Dropdown
$listing->baths_id = ''; // Dropdown
$listing->pet_id = ''; // Dropdown
$listing->type_id = ''; // Dropdown
$listing->owner_id = ''; // Dropdown
$listing->web_id = 'CWA' . random_string('numeric', 7); // varchar
$listing->featured = ''; // bool
$listing->deal_id = '0'; // bool
$listing->price = ''; // int
$listing->convertible = ''; // bool
$listing->dateAvailable = ''; // Only to populate visible jQuery datapicker
$listing->available = ''; // date
$listing->sqft = ''; // int
$listing->address = ''; // varchar
$listing->unit = ''; // varchar
$listing->description = ''; // text
$listing->zip = ''; // int
$listing->notes = ''; // text
$listing->amenity_ids['unit'] = array(); // Dropdown
$listing->amenity_ids['property'] = array(); // Dropdown
$listing->image_ids = array();
return $listing;
}
I don't know about your data model. You should post it here. If your data model has been done correctly, then this is the line that would change:
$this->db->join('images', 'images.image_id = listings.image_id', 'left');
to
$this->db->join('images', 'images.listing_id = listings.id');
You should store the listing ID in the Images table rather than the other way round.
EDIT:
From data model, I mean database structure. If there are n images for every single 'listing', then you need to store a reference to the 'listing ID' in the 'images' table.
Took over this project from someone else. Where would I add fields to the image table. Right now in CMS it shows multiple images for a listing. The code is:
<?php foreach ($images as $image): ?>
<li data-image-id="<?=$image -> image_id ?>" class="uploaded-image" id="image_<?=$image -> image_id ?>">
<div class="sortableimagewrapper">
<!-- <span class="label label-inverse image-name"> </span> -->
<img src="<?=images_url('110x68/' . $image -> file_name) ?>" alt="" width="110px" height="68px" class="img-polaroid" />
<div class="btn-group">
<button class="btn <?php
if ($image -> image_id == $listing -> image_id)
echo 'btn-warning';
?> image-default"><span class="icon-star <?php
if ($image -> image_id == $listing -> image_id)
echo 'icon-white';
?>"></span></button>
<button class="btn image-remove"><span class="icon-remove"></span></button>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>

Resources