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

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 9,652
» Latest member: esobrevilla
» Forum threads: 66,773
» Forum posts: 418,537

Full Statistics

Latest Threads
Dynamic Meta Description
Forum: General Help
3 hours ago
» Replies: 1   » Views: 39
redis driver _get_lock se...
Forum: Issues
4 hours ago
» Replies: 6   » Views: 150
Release date for 3.2.0?
Forum: CodeIgniter 3.x
4 hours ago
» Replies: 1   » Views: 87
How do you access the $th...
Forum: CodeIgniter 4 Discussion
Yesterday, 08:25 PM
» Replies: 7   » Views: 313
new User of CodeIgniter
Forum: Lounge
Yesterday, 07:57 PM
» Replies: 2   » Views: 107
Login library
Forum: Best Practices
Yesterday, 05:18 PM
» Replies: 3   » Views: 219
myBB and CI logins
Forum: Lounge
Yesterday, 05:17 PM
» Replies: 2   » Views: 132
Improve Pagination CI 3x
Forum: CodeIgniter 3.x
Yesterday, 01:58 PM
» Replies: 1   » Views: 121
input post empty
Forum: General Help
Yesterday, 10:24 AM
» Replies: 8   » Views: 183
Share Vuejs Route with Co...
Forum: General Help
Yesterday, 07:24 AM
» Replies: 1   » Views: 106

 
  Model query with two possible inputs
Posted by: El Forum - 07-31-2007, 01:50 PM - Forum: Archived Development & Programming - Replies (3)

[eluser]kirkaracha[/eluser]
I have a list of countries I can access publicly or via a password-protected admin backend. I want to access the countries by URL name from the front end for SEO/usability reasons, and I want to access them by ID on the backend (in case I need to edit the URL name). Here's the query from my model:

Code:
function get_country_info($country_id = null,$country_url_name = null) {
    $this->db->select('
        country_id,
        country_name,
        country_url_name
    ');
    $this->db->from('countries');
    if($country_id != null){
        $this->db->where('country_id',$country_id);
        $this->db->limit('1');
    }
    if($country_url_name != null){
        $this->db->where('country_url_name',$country_url_name);
        $this->db->limit('1');
    }
    return $this->db->get();
} // get_country_info
This works fine if I use ID, but doesn't return any records when I use the URL name. Is there something wrong with my model? How should I do this?

Thanks.


  Profiler bug line 168 - 169
Posted by: El Forum - 07-31-2007, 12:58 PM - Forum: Archived Development & Programming - Replies (8)

[eluser]Jamongkad[/eluser]
As I have posted on the freakauth 1.1 thread

Quote:@DanFreak

Since we're in the process of fine tuning Fal I would like to introduce another niggle hehe. Once I got the myaccount/edit controler/method working. CI seems to spout out a strange but interesting error.

Code:
Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\myswebsite\system\libraries\Profiler.php on line 169

Upon inspection of this of Profiler.php line 169
Code:
line 168://$output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>$_POST[".$key."]&nbsp;&nbsp;</td><td width='50%' style='color:#009900;font-weight:normal;background-color:#ddd;'>".htmlspecialchars(stripslashes($val))."</td></tr>\n";

line 169:$output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>$_POST[".$key."]  </td><td width='50%' style='color:#009900;font-weight:normal;background-color:#ddd;'>";

It seems line 168 was commented out to make room for line 169. So as an experiment decided to comment out line 169 as well and lo and behold it worked! but there was this weird benchmark result that comes out of the bottom of the edit form..

please click on link below(sorry I don't know how does this forum display images).
[Image: error.jpg]
A pic of the error in this link:
[Image: error.jpg]

My tools:
Code Igniter 1.5.3
FreakAuth_light_1.1

I will attempt to fix this on my own :-) but help from Rick and the gang would be nice.


  troubles with cookies
Posted by: El Forum - 07-31-2007, 12:56 PM - Forum: Archived General Discussion - Replies (8)

[eluser]andycorpes[/eluser]
Hi Group

I'm new to CI, and relatively new to PHP, however, using raw php i CAN get cookies to work.

Using CI, i can set cookies, but cannot seem to retrieve them afterwards. Are there any "gotchas" using the CI cookie helper? or am i just being dumb after a long day? I've tried various "lifetimes", from -1 to delete the rubbish i created, through to 315360000 (10 years?)

Originally, i coded this using the session class, which all worked, however, i needed one set of session variables to live for 24 hours, and the other set to live forever (Hence 10 years). I encountered problems with the session class where ALL session variables got the same lifetime, i.e i wrote the 24 hour session variables, and it changed the life time of my 10 year session variables.

If anyone understands what i am trying to do, and knows of an alternative approach, i'd be happy to try it.

Hopefully, fresh eyes will solve my problems tomorrow.

Andy Corpes


  form GET
Posted by: El Forum - 07-31-2007, 11:32 AM - Forum: Archived General Discussion - Replies (1)

[eluser]AndyBrandy[/eluser]
Hi,

how can i easily make search form like http://www.google.com?

Because i have problem when data were send, than page http://example.com/search?q=ci
is not found... Only with &lt;form method=POST&gt; ?


  Can be method used as id?
Posted by: El Forum - 07-31-2007, 11:05 AM - Forum: Archived General Discussion - Replies (6)

[eluser]AndyBrandy[/eluser]
Hi,

Can i use method as id or parameter?
I need From this url : example.com/text/programing/1/

go to the class "text" and here goes to index.

It's real?


  Comments on my first CI application (Calendar/event)
Posted by: El Forum - 07-31-2007, 11:00 AM - Forum: Archived Development & Programming - Replies (2)

[eluser]tobben[/eluser]
Hi,

first I must give my respect to the guys behind this framework. I really love it so far.


Second: the topic issue. I've just puzzled together something that atleast looks like a event calendar.

It works, _but_ I want to get some feedback on the structure and inprovments for the logic, so I can go further in the learning process.


// THE CONTROLLER (kalender.php)

Code:
class Kalender extends Controller {

    // Constuctor

    function __construct()
    {
        parent::Controller();

        $this->load->library('calendar');
        $this->load->model('kalender_model');
    }

    // index

    function index()
    {
        redirect('kalender/dato/'. date('Y') . '/' . date('m') . '/','location');
    }

    function dato()
    {    
        // Grab some vars

        $cal_year = $this->uri->segment(3);
        $cal_month = $this->uri->segment(4);
        $cal_day = $this->uri->segment(5);


        // Check if is numeric

        if(!empty($cal_year) && ctype_digit($cal_year) == FALSE)
        {
            redirect('kalender/dato/'. date('Y') . '/' . date('m') . '/','location');
        }

        if(!empty($cal_month) && ctype_digit($cal_month) == FALSE)
        {
            redirect('kalender/dato/'. date('Y') . '/' . date('m') . '/','location');
        }

        if(!empty($cal_day) && ctype_digit($cal_day) == FALSE)
        {
            redirect('kalender/dato/'. date('Y') . '/' . date('m') . '/','location');
        }

        // Redirect if empty vars

        if(!$cal_year || !$cal_month)
        {    
            redirect('kalender/dato/'. date('Y') . '/' . date('m') . '/','location');
        }


        // Setup calendar

        $prefs = array (
            'start_day'    => 'monday',
            'month_type'   => 'long',
            'day_type'     => 'abr',
            'show_next_prev'  => TRUE,
            'next_prev_url'   => base_url() . 'kalender/dato/'
            );

        $this->calendar->initialize($prefs);


        // Say hello to the models

        $data['event_data'] = $this->kalender_model->get_events($cal_year, $cal_month);

        // If day isset, get day info

        if($cal_day)
        {
            $data['event_day_data'] = $this->kalender_model->get_day($cal_year, $cal_month, $cal_day);    
        }


        // Tell it to the viewer

        $this->load->view('kalender_view', $data);

    }

}


// THE MODEL (kalender_model.php)

Code:
class Kalender_model extends Model {

    // Constuctor

    function __construct() {

        parent::Model();

    }

    function get_events($year, $month) {

        $first_day = mdate('%Y-%m-%d', mktime(0,0,0,$month,1,$year));
        $last_day = mdate('%Y-%m-%d', mktime(0,0,0,$month,days_in_month($month, $year),$year));

        $this->db->where('event_date >', $first_day);
        $this->db->where('event_date <', $last_day);
        $query = $this->db->get('kalender');

        if ($query->num_rows() > 0)
        {
            foreach($query->result() as $k => $row)
            {
                $key = mdate('%j', mysql_to_unix($row->event_date));

                $data_array[$key] = base_url() . 'kalender/dato/' . $year . '/' . $month . '/' . str_pad($key, 2, '0', STR_PAD_LEFT);
            }

            return $data_array;
        }
    }

    function get_day($year, $month, $day) {

        $first_day = mdate('%Y-%m-%d', mktime(0,0,0,$month,1,$year));
        $last_day = mdate('%Y-%m-%d', mktime(0,0,0,$month,days_in_month($month, $year),$year));
        $current_day = mdate('%Y-%m-%d', mktime(0,0,0,$month,$day,$year));

        $this->db->where('event_date =', $current_day);
        $query = $this->db->get('kalender');

        if ($query->num_rows() > 0)
        {
            foreach($query->result() as $k => $row)
            {
                $key = mdate('%d', mysql_to_unix($row->event_date));

                $data_array[$k]['dato'] = base_url() . 'kalender/dato/' . $year . '/' . $month . '/' . $key;
                $data_array[$k]['body'] = $row->body;
                $data_array[$k]['title'] = $row->title;
            }

            return $data_array;
        }
    }
}



// THE VIEW (kalender_view.php)

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="no" lang="no"&gt;
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
    &lt;meta name="robots" content="index,follow" /&gt;
    &lt;meta name="description" content="" /&gt;
    &lt;meta name="keywords" content="" /&gt;

    &lt;title&gt;Title&lt;/title&gt;
    
&lt;/head&gt;

&lt;body&gt;

    <div id="container">

    &lt;?php
    
    echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4), $event_data);
    
    if($this->uri->segment(5)){
        
        foreach($event_day_data as $value) {
            echo '<h2>' . $value['title'] . '</h2>';
            echo '<p>' . $value['body'] . '</p>';
        }    
    }
    
    ?&gt;

    </div>

&lt;/body&gt;
&lt;/html&gt;


Well, that's all folks, and thanks for all the fish.


  there can be only one auto column and it must be defined as a key
Posted by: El Forum - 07-31-2007, 10:38 AM - Forum: Archived Development & Programming - Replies (5)

[eluser]sikkle[/eluser]
Does anyone here already deal with simulation of two or three auto_increment field ?

like

unique id starting at 1
unique serial no starting at 100 000 001
unique client public number starting at 100 000 000 001


How do people deal with this ?

Thanks !


  Pass data between functions
Posted by: El Forum - 07-31-2007, 10:09 AM - Forum: Archived Development & Programming - Replies (5)

[eluser]Stuart Marsh[/eluser]
Can anybody tell me how I can pass data between controllers quickly and efficiently?
I have two controllers. Controller A displays a form and validates the data. I want controller A to redirect the page and pass the form data to controller B.
I dont really want to pass the data through the URI, but will if there is no other way.
Anybody got any suggestions?

Cheers.


  problem with chars in classes
Posted by: El Forum - 07-31-2007, 09:47 AM - Forum: Archived General Discussion - Replies (1)

[eluser]AndyBrandy[/eluser]
Hello,

i have on my old blog some urls like this: http://example.com/class-first/

When i create controller "class-first", it must have name "Class-first".
But it returns error: Parse error: syntax error, unexpected '-', expecting '{' in /data/www/test.ex/system/application/controllers/class-first.php on line 3

What can i do when i don't want change url?


  [PLUGIN] Excel plugin extended to arrays.
Posted by: El Forum - 07-31-2007, 09:25 AM - Forum: Archived Development & Programming - Replies (1)

[eluser]Morty[/eluser]
Please refer to http://codeigniter.com/wiki/Excel_Plugin/ for original plugin.

Following my last needs (see older threads), I took my own hands to modify a little this plugin. It now should accept three different data sources :

- Queries : default type and therefore backward compatible ;
- Associative array :
=> table[0]['Number'] => 1 ;
=> table[0]['Information'] => 'Blabla1' ;
=> table[1]['Number'] => 3 ;
=> table[1]['Information'] => 'Blabla2' ;
- Arrays :
=> $array['headers'] containing headers ;
=> $array['data'] containing data (nice titling isn't it?) ;

It can be summoned by using to_excel($source, $filename, $type = 'query' or 'assoc_array' or 'array').

Now for the code :

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

/*
* Excel library for Code Igniter applications
* Author: Derek Allard, Dark Horse Consulting, www.darkhorse.to, April 2006
* Modification: Hadrien Debris, Archos S.A., July 2007
*/

function is_obj(&$object, $check = null, $strict = true)
{
    if (is_object($object))
    {
        if ($check == null)
        {
            return true;
        }
        else
        {
            $object_name = get_class($object);
            return ($strict === true) ? ($object_name == $check):(strtolower($object_name) ==
                strtolower($check));
        }
    }
    else
    {
        return false;
    }
}

function row_record($row)
{
    $line = '';
    foreach ($row as $value)
    {
        if ((!isset($value)) || ($value == ""))
        {
            $value = "\t";
        }
        else
        {
            $value = str_replace('"', '""', $value);
            $value = '"' . $value . '"' . "\t";
        }
        $line .= $value;
    }
    return ($line);
}

function to_excel($source, $filename = 'exceloutput', $type = 'query')
{
    $headers = '';// just creating the var for field headers to append to below
    $data = '';// just creating the var for field data to append to below
    $test_passed = false;// validating datasource

    $obj = &get;_instance();

    if (($type == 'query') && (is_obj($source, "CI_DB_mysql_result")))
        // we're passing a normal query
    {
        $fields = $source->field_data();
        $test_passed = true;
    }
    elseif (($type == 'assoc_array') && (is_array($source)))
        // information is held in an associative array
    {
        $fields = array_keys($source[0]);// We take our first record's headers
        $test_passed = true;
    }
    elseif (($type == 'array') && (isset($source['headers'])) && (is_array($source)))
        // headers and data are separated
    {
        $fields = $source['headers'];
        $test_passed = true;
    }
    else
        echo '<p>Incorrect <b>$type</b> parameter.</p>';

    if ($test_passed)
    {
        $result_check_query = (($type == 'query') && ($source->num_rows() == 0));
        $result_check_array = (is_array($source)) && (((count($source) == 0)) || (!isset($source['data'])));

        if ($result_check_query || $result_check_array)
        {
            echo '<p>The table appears to have no data.</p>';
        }
        else
        {
            if ($type == 'query')
            {
                foreach ($fields as $field)
                {
                    $headers .= $field->name . "\t";
                }

                foreach ($source->result() as $row)
                {
                    $data .= trim(row_record($row)) . "\n";
                }
            }
            elseif ($type == 'assoc_array')
            {
                foreach ($fields as $field)
                {
                    $headers .= $field . "\t";
                }
                foreach ($source as $header => $row)
                {
                    $data .= trim(row_record($row)) . "\n";
                }
            }
            else
            {
                foreach ($fields as $field)
                {
                    $headers .= $field . "\t";
                }
                foreach ($source['data'] as $row)
                {
                    $data .= trim(row_record($row)) . "\n";
                }
            }

            if ($headers != '') // Allow results with no headers
                $headers .= "\n";
            $data = str_replace("\r", "", $data);

            header("Content-type: application/x-msdownload");
            header("Content-Disposition: attachment; filename=$filename.xls");
            echo $headers;
            echo $data;
        }
    }
    else
    {
        echo ('Error when submitting your datasource : ');
        echo (var_dump($source));
        return false;
    }
}
?&gt;

I did not have time to test it completely, so please report bugs and features you might want added. I am not a PHP-maniac so there could be novice errors in there.

Thanks in advance for your feedback.

Edit/P.S. : I was thinking about allowing headers with "colspan" or extraheadcontent but I don't know if it is either useful or if it can easily be added.



  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.