Welcome Guest, Not a member yet? Register   Sign In
  Please Help!!! one to many relationships?
Posted by: El Forum - 09-10-2008, 02:59 AM - Replies (2)

[eluser]Unknown[/eluser]
Hi everyone,

I am pretty new to code igniter but have some experience with PHP. This is my first production app using CI and I have stumbled at the 1st hurdle.

I am trying to make a system to distribute tasks to employee's. When a new task is loaded in the system I want the user to be able to click a button/link then send the same task to 5 employee's.

The DB will have 3 tables Tasks_table, Staff_table, and Assigned_Tasks_table.

The Assigned_Tasks table will store the key's from the other 2 tables (kinda like a shopping cart).
I have extracted the task_id from the URI and can write that to the Assigned-tasks table, I have also run a query to extract 5 employees with the least number of current tasks.

How do I take the output from this query and insert the staff_id fields of the 5 results into 5 records of the assigned_tasks table?

I hope someone can help, I am really stuck!!

Any questions please ask!


  What is .= ?
Posted by: El Forum - 09-10-2008, 02:58 AM - Replies (6)

[eluser]phantom-a[/eluser]
Sorry this may sound real dumb but I cannot find anything on google becuase Google doesn't return results for symbols like "=", so I can't put "what is .= in php" Wink



$var .=


what is that . (dot) beside the equal sign?


  Error in paging
Posted by: El Forum - 09-10-2008, 02:48 AM - No Replies

[eluser]novarli[/eluser]
My controller script

Code:
$data['count_result'] = $this->cities->count_result($txtName,$province);
    $config['total_rows'] = $data['count_result'];
    $config['per_page'] = 2;    
    $offset = $this->uri->segment(3);
    $this->load->library('pagination');
    $this->pagination->initialize($config);
    $data['paging'] = $this->pagination->create_links();  
    $data['search_res'] = $this->cities->getSearchResult($txtName,$province, $config['per_page'], $offset);
    
    
    $this->load->view('city/search_res', $data);

The model
Code:
function getSearchResult($city,$province,$limit,$offset){
    $this->db->select('cities.id,cities.name as city_name,provinces.name as province_name');
    $this->db->from('cities');
    $this->db->join('provinces','cities.province = provinces.id');
        if (!empty($city))
        {
            $this->db->like('cities.name',$city);
            
        }
        
        if ($offset)
        {
            $this->db->limit($limit,$offset);        
        }
        else
        {
            $this->db->limit($limit);        
        }
        if ($province!=0){
         $this->db->where('province', $province);
        
        }
    $this->db->order_by('cities.name');    
    $query = $this->db->get();
    return $query->result();
    }
    
    function count_result($city,$province)
    {
    $this->db->select('cities.id,cities.name as city_name,provinces.name as province_name');
    $this->db->from('cities');
    $this->db->join('provinces','cities.province = provinces.id');
        if (!empty($city))
        {
            $this->db->like('cities.name',$city);
        }
        if ($province!=0){
         $this->db->where('province', $province);
        }
    return $this->db->get();        
    }

And view
Code:
...
<?php echo !empty($paging) ? $paging : ''; ?>

then error

Message: Object of class CI_DB_mysql_result could not be converted to int

Filename: libraries/Pagination.php

Line Number: 104

Severity: Notice

Message: Object of class CI_DB_mysql_result could not be converted to int

Filename: libraries/Pagination.php

Line Number: 110

What happen?

Here the screenshot
http://img364.imageshack.us/img364/7103/resultzb0.gif


  Custom 404 handling
Posted by: El Forum - 09-10-2008, 02:09 AM - Replies (18)

[eluser]Mark van der Walle[/eluser]
After almost 2 years of using CI and posting a bit on these forums I present my first contribution to the community. It is a simple custom 404 handler that can be used to handle any path that cannot be routed to a controller. It uses an overrided Router, base controller and the _remap function. Suggestions, critics are welcome Smile

Base controller:

Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Controller extends Controller
{
    /**
     * Constructor
     */
    public function __construct()
    {
        parent::Controller();
    }

    /**
     * @param   string          $method the method CI would usually call
     */
    public function _remap($method)
    {
        global $URI;

        if (method_exists($this, $method)) {
            call_user_func_array(array(&$this, $method), array_slice($URI->rsegments, 2));
        } else {
            $this->_handle_404();
        }
    }

    /**
     * Handle 404 using a custom controller. Will call default show_404() when it cannot resolve to a valid method.
     */
    protected function _handle_404()
    {
        $errorconfig = $this->config->item('error');

        if (!$errorconfig) {
            show_404();
        }

        $path = APPPATH . 'controllers/' . $errorconfig['directory'] . '/' . $errorconfig['controller'] . EXT;
        if (!file_exists($path)) {
            show_404();
        }

        require_once $path;
        if (!class_exists($errorconfig['controller'])) {
            show_404();
        }

        $class = new $errorconfig['controller'];
        if (!method_exists($class, $errorconfig['method'])) {
            show_404();
        }

        call_user_func(array(&$class, $errorconfig['method']));
    }
}
?>

Router:
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Router extends CI_Router
{
    /**
     * Validates the supplied segments.  Attempts to determine the path to
     * the controller. This is an extension so we can support 404 handlers
     *
     * @access    private
     * @param    array
     * @return    array
     */    
    function _validate_request($segments)
    {
        // Does the requested controller exist in the root folder?
        if (file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            return $segments;
        }

        // Is the controller in a sub-folder?
        if (is_dir(APPPATH.'controllers/'.$segments[0]))
        {        
            // Set the directory and remove it from the segment array
            $this->set_directory($segments[0]);
            $segments = array_slice($segments, 1);
            
            if (count($segments) > 0)
            {
                // Does the requested controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$segments[0].EXT))
                {
                    return $this->_custom_404();    
                }
            }
            else
            {
                $this->set_class($this->default_controller);
                $this->set_method('index');
            
                // Does the default controller exist in the sub-folder?
                if ( ! file_exists(APPPATH.'controllers/'.$this->fetch_directory().$this->default_controller.EXT))
                {
                    $this->directory = '';
                    return array();
                }
            
            }
                
            return $segments;
        }
    
        // Can't find the requested controller...
        return $this->_custom_404();    
    }

    function _custom_404()
    {
        $errorconfig = $this->config->item('error');

        if ($errorconfig) {

            $path = APPPATH . 'controllers/' . $errorconfig['directory'] . '/' . $errorconfig['controller'] . EXT;
            if (file_exists($path)) {
                $this->set_directory($errorconfig['directory']);
                $this->set_class($errorconfig['controller']);
                $this->set_method($errorconfig['method']);
            } else {
                show_404();
            }
        } else {
            show_404();
        }

        return array();
    }
}
?>

Errorhandler controller:
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class ErrorHandler extends MY_Controller
{
    function index()
    {
        // You could do basicly anything here. Pull content from databases
        // using the supplied path and/or read text files. or just show your
        // own fancy 404 page. For now we just:

        echo '404';
    }
}
?>

And finally some config:
Code:
$config['error']['directory'] = '';

$config['error']['controller'] = 'errorhandler';

$config['error']['method'] = 'index';


  When the database changes, the page will reload..
Posted by: El Forum - 09-10-2008, 01:00 AM - Replies (7)

[eluser]magz[/eluser]
Hi all,

Is there any way or technology that can do as it is said in the title (When the database changes, the page will update) ?. We build a simple chat application using ajax. But it cause traffic due to alot of request to the server.

So we come up with that idea.. if there are updates, insert or delete happens in the database the page will just update automatically without repeatedly requesting to server..

is there any way we can achieve that idea??..

Any help will be appreciated..
thnx..


  Question on auth check with simplelogin
Posted by: El Forum - 09-10-2008, 12:42 AM - Replies (11)

[eluser]San2k[/eluser]
Hi!
Didn't find an answer on forums (maybe i looked bad Wink)

I have a problem with checking if user is logged in. So i'am doing this:

Code:
class MyPROG extends Controller {


        function MyPROG ()
    {
        parent::Controller();
             $user_table = 'users';
         $this->load->helper(array('form', 'url'));

         if(!$this->session->userdata('logged_in')){
         $this->load->view('header');
         $this->load->view('login');
        }
    }

It checks correctly, but the problem is - that if user is NOT logged,
$this->load->view('header');
$this->load->view('login');
- this two view files will be loaded + my Index function will be loaded too.

Code:
function index()
    {
     $this->load->view('header');
     $this->load->view('add_employer');

    }

if i put exit; after $this->load->view('login'); in main function - nothing loads at all.

My main idea, why i did it that way - is that MyPROG runs before any function in controller(is that right?) - so its the best place to check login. so noone can access any functions bypassing login check.

Thanks.


  Data Storage Object PHP5
Posted by: El Forum - 09-10-2008, 12:10 AM - Replies (2)

[eluser]wiredesignz[/eluser]

Code:
<?php
/**
* Data Storage Object PHP5
*
* This library can be used to store and retrieve sets of data.
*
* Use in views or anywhere where you may have an incomplete dataset
* it will prevent undefined variable errors. ie: Use in forms during insert.
*  
* Example:
* $user = new DataStore($this->user_model->get('Admin'));
* $user->languages = $this->language_model->get($user->id);
*
* @version: 0.2 (c) Wiredesignz 2008-09-10
*/
class DataStore
{
    private $datastore;
    
    public function __construct($data = array())
    {
        $this->datastore = $data;
    }

    public function __set($key, $data = NULL)
    {
        if (is_array($this->datastore))  
            
            $this->datastore[$key] = $data;
        
        if (is_object($this->datastore))
        
            $this->datastore->$key = $data;
    }
    
    public function __get($key)
    {
        if (is_array($this->datastore) AND isset($this->datastore[$key]))
        
            return $this->datastore[$key];
        
        if (is_object($this->datastore) AND isset($this->datastore->$key))
        
            return $this->datastore->$key;
            
        return NULL;
    }
}


  smileys
Posted by: El Forum - 09-09-2008, 11:52 PM - Replies (1)

[eluser]Unknown[/eluser]
How can i insert smileys in my message?..
Error is coming like "Undefined table data"..
please help me..


  Messenger using Code Igniter
Posted by: El Forum - 09-09-2008, 11:49 PM - Replies (3)

[eluser]Unknown[/eluser]
I want to develop one simple messenger using code igniter..
how can i develop it so that messages are displayed automatically without pressing refresh button of browser?.
please help me..


  Need Help on Creating Whiteboard Effect
Posted by: El Forum - 09-09-2008, 11:40 PM - No Replies

[eluser]Mizanur Islam Laskar[/eluser]
Hi Experts,

I need to build up a system where an uploaded image will be shown and user can draw on it by draging his mouse. Then user will also be able to save the edited image by replacing the old one. You can call it a Whiteboard Effect. I need to develope it in CI, but if flat code is available, then I can try myself to modify it in CI. So experts, I need your help.


Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Latest Threads
request URL not found
by jcarvalho
23 minutes ago
Cannot access protected p...
by xsPurX
50 minutes ago
Trying to remove index.ph...
by demyr
2 hours ago
Convert Filters to Regist...
by Willen
3 hours ago
MaintenanceFilter vs Java...
by Gary
6 hours ago
Top 10 PHP Testing Framew...
by FlavioSuar
Yesterday, 04:00 AM
CL4 Connecting to a Remot...
by cx3700
05-01-2024, 07:33 PM
codeigniter.com/user_guid...
by kenjis
05-01-2024, 07:29 PM
As experienced web develo...
by kenjis
05-01-2024, 06:03 PM
Filters in filters folder...
by xsPurX
05-01-2024, 03:01 PM

Forum Statistics
» Members: 86,232
» Latest member: moversandpackersindubai
» Forum threads: 77,606
» Forum posts: 376,137

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB