Welcome Guest, Not a member yet? Register   Sign In
  Autocomplete on CodeIgniter 1.5.4
Posted by: El Forum - 04-11-2008, 02:51 PM - Replies (7)

[eluser]mexor[/eluser]
I tried this
http://video.derekallard.com/

Auto completer on CodeIgniter 1.5.4 but couldn't get it to work.
Nothing shows up in the autocomplete, and no functions show up in the DIV after searching.

I've asked a few people who have used codeIgniter a lot and they couldn't get it to work either. Anyone have any suggestions on what would make it work?

Thanks
Dave


  I need some help with IPBSDK
Posted by: El Forum - 04-11-2008, 12:18 PM - No Replies

[eluser]CrazeD[/eluser]
Hi, new here...

Okay so, I'm trying to use IPBSDK with Codeigniter. If you aren't familiar with IPBSDK, it is a very useful class for integrating Invision Power Boards into your main website. It includes login/logout functions, getting info... tons of useful stuff.

Now, I've made it work, but in a troublesome way. I have a header and footer PHP files for my template, then I just slip in the current page in the middle. My controller for any given page looks like so:

Code:
class Test extends Controller {

    function index() {
        $this->load->view('header');
        $this->load->view('test');
        $this->load->view('footer');
    }
}

Now, I couldn't get the SDK to load with the $this->load->library function, so I just included the class on the main index.php file, which works fine.

So, my header and footer files both have to call the IPBSDK class, like so:

Code:
$SDK = new IPBSDK;

I have that at the beginning of both files. Most of my pages also require this, so I have to have it at the beginning of those pages as well.

Most of the SDK functions work great, except login/logout functions. It is because I called the IPBSDK class in the header, footer, and current page files. If I do this it works:

Code:
class Test extends Controller {

    function index() {
        $SDK = new IPBSDK;
        $data['SDK'] = $SDK;
        $this->load->view('header',$data);
        $this->load->view('test',$data);
        $this->load->view('footer',$data);
    }
}

Now, everything works.

However I don't want to have to do that for every controller, is there anyway I can call this class from one location and have it available on all pages?

Thanks.


  Strange callback validation error for an array
Posted by: El Forum - 04-11-2008, 11:16 AM - Replies (1)

[eluser]Isos[/eluser]
In a user profile, user is asked to check at least 5 checkboxes out of 30.
The checkboxes are named as discplines[] as following:

Code:
<input type="checkbox" name="disciplines[]" value="<?$discipline->id;?>" />
It means $_POST['disciplines'] is an array of disciplines IDs
So I created a callback functions as following:
Code:
function _check_if_more_than_five($str){
    if (count($str) > 5){
         $this->validation->set_message("_check_if_more_than_five","You cannot check more than five disciplines");

            return false;
        } else {
            return true;
        }

    }

The good thing about this is that it works, but the bugging ugly thing is that I get this error at the top of the page:

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: libraries/Validation.php

Line Number: 709



Where Line Number: 709 in libraries/Validation.php is as following:
Code:
return str_replace(array("'", '"', '<', '>'), array("'", "&quot;", '&lt;', '&gt;'), stripslashes($data));
The whole function is as following:
Code:
/**
     * Prep data for form
     *
     * This function allows HTML to be safely shown in a form.
     * Special characters are converted.
     *
     * @access    public
     * @param    string
     * @return    string
     */
    function prep_for_form($data = '')
    {
        if (is_array($data))
        {
            foreach ($data as $key => $val)
            {
                $data[$key] = $this->prep_for_form($val);
            }
        }
        
        if ($this->_safe_form_data == FALSE OR $data == '')
        {
            return $data;
        }

        return str_replace(array("'", '"', '<', '>'), array("'", "&quot;", '&lt;', '&gt;'), stripslashes($data));
    }

I am trying to figure out what's wrong and how I may solve this. But, when it comes to manipulating a ci script to solve a problem I tend to consult in here.

Any help will be appreciated.

Thanks.


  Problem with a db query
Posted by: El Forum - 04-11-2008, 10:23 AM - Replies (1)

[eluser]Unknown[/eluser]
I have a problem with one query.

I have this code:

Code:
$this->db->select("f.*, (SELECT GROUP_CONCAT (CONCAT(p.nome, ' ', p.cognome) SEPARATOR ', ')
                         FROM professionisti p
                                                 WHERE p.id IN (SELECT r.id_professionista FROM registi r WHERE r.id_film = f.id)
                                                ) AS regista", FALSE);
$this->db->from($this->tables['film'] . ' f');
$this->db->where("f.pagina_html = '" . $film . "'");
$sql = $this->db->get();
return $sql->row();

but the above code return me the following error:

Quote:An Error Was Encountered

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SEPARATOR ', ') FROM professionisti p ' at line 1

SELECT f.*, (SELECT GROUP_CONCAT (CONCAT(p.nome, ' ', p.cognome) SEPARATOR ', ') FROM professionisti p WHERE p.id IN (SELECT r.id_professionista FROM registi r WHERE r.id_film = f.id) ) AS regista FROM (`film` f) WHERE f.pagina_html = 'grindhouse_us_version'

the query reported in the error message don't have problem in phpmyadmin.

I also tried with the following code:

Code:
$sql = "SELECT f.*, (SELECT GROUP_CONCAT (CONCAT(p.nome, ' ', p.cognome) SEPARATOR ', ')
FROM professionisti p
WHERE p.id IN (SELECT r.id_professionista FROM registi r WHERE r.id_film = f.id)
) AS regista
FROM film f
WHERE f.pagina_html = '" . $film . "'";
$query = $this->db->query($sql);

but return me the same error.

Where is the problem?


PS: excuse me for my english. I hope you can understand what i wrote.


  search with pagination: POST first, then GET?
Posted by: El Forum - 04-11-2008, 09:38 AM - Replies (1)

[eluser]Unknown[/eluser]
First of all, thanks to all the contributors to this forum
I've found it invaluable in my first CI project!

Ok, so I have a search page with pagination running fine

http://www.mysite.com/jobs/search/css:html/london
http://www.mysite.com/jobs/search/css:html/london/4
etc;

I might change it to
http://www.mysite.com/jobs/search/for/cs...n/offset/4
and then use $this->uri->uri_to_assoc(n)
if it helps my problem below.

But what I'm not sure about is when I want to call this URL
from a simple search form on the same page.

Should I use a GET method on the form and then try and turn
http://www.mysite.com/jobs/search?for=cs...n&offset=4
into
http://www.mysite.com/jobs/search/for/cs...n/offset/4
using htaccess or the routing feature of CI?

or should I use
some logic in the controller to check if it was a POST or GET
it's further comlicated because I would like to use the validation library to check if the fields are empty.

Any advice greatly appreciated,
Thanks.


This is the method in my controller

Code:
function search()
   {
    $this->output->enable_profiler(TRUE);
  
       $segs = $this->uri->segment_array();
    $search_txt = $this->uri->segment(3, 'all');
    $search_terms = explode(":",$this->uri->segment(3));    
    $search_location = $this->uri->segment(4, 'any');
    $search_offset = $this->uri->segment(5, 0);
    
    
        $this->load->helper(array('form', 'url'));
        $this->load->library('validation');
        
        $fields['for'] = 'for';
        $fields['location'] = 'location';
        $this->validation->set_fields($fields);
        
        $rules['for'] = 'required';
        $this->validation->set_rules($rules);
        
        $data['page'] = 'search';
        $data['header'] = $this->load->view('includes/header', $data, true);

    // pagination
    $this->load->library('pagination');
    $config['base_url'] = base_url().$this->uri->slash_segment(1, 'leading').$this->uri->slash_segment(2, 'both').$search_txt.'/'.$search_location.'/'; // cahnge to url
    $config['total_rows'] = $this->db->count_all('jobs');
    $config['per_page'] = '2';
    $config['full_tag_open'] = '<p>';
    $config['full_tag_close'] = '</p>';
    $config['num_links'] = 2;
    $config['uri_segment'] = $this->uri->total_segments();
    $this->pagination->initialize($config);
    // load jobs model
    $this->load->model('jobs_model', '', TRUE);
    $data['results'] = $this->jobs_model->get_jobs($search_terms,$config['per_page'],$search_offset);
    
    $data['pagination'] = $this->pagination->create_links();
    $this->load->view('search', $data);

  }


  [SOLVED] Upload 2 files with diferent configuration
Posted by: El Forum - 04-11-2008, 09:36 AM - Replies (2)

[eluser]Lagarto[/eluser]
I'm trying to upload (using file upload library) 2 files from the same form, but each of this files have a diferent "config", i've tested this code and it seems that only take the first config/library loading.

Code:
$config['upload_path'] = 'public/uploaded';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']    = '10000';
$config['max_width']  = '190';
$config['max_height']  = '125';
//$config['max_width']  = '600';
//$config['max_height']  = '395';                

$this->load->library('upload', $config);

if($this->upload->do_upload("img_thumb"))
{
    //agafo nom d'abans
    $data = $this->upload->data();
    $nom_thumb = $data['file_name'];

    $config['upload_path'] = 'public/uploaded';
    $config['allowed_types'] = 'gif|jpg|png|swf';
    $config['max_size']    = '10000';
    $config['max_width']  = '600';
    $config['max_height']  = '395';
    
    $this->load->library('upload', $config);

    if($this->upload->do_upload("img_gran"))
    {
        //agafo nom d'abans
        $data = $this->upload->data();
        $nom_gran = $data['file_name'];
        //insert
        $nombre = $_POST['nombre'];
        $fecha = time();
        $idioma=1;
        $texto = $_POST['texto'];
        $insert = array($nombre, $fecha, $idioma, $texto, $nom_thumb, $nom_gran);
        $this->db->query("INSERT INTO `realisations` (`nombre`, `fecha`, `idioma`, `texto`, `img_thumb`, `img_gran`) VALUES (?, ?, ?, ?, ?, ?)", $insert);
        redirect('realisations/index/created_ok');
    }    
    else
    {
        redirect('realisations/add/error_ok/2');
        //echo $this->upload->display_errors();
    }
}    
else
{
    redirect('realisations/add/error_ok/1');
    //echo "error 1";
    //echo $this->upload->display_errors();
}

Am I doing something wrong? Bug spotted?

Thanks! Big Grin


  Sending both HTML and Plain Text Email at the same time
Posted by: El Forum - 04-11-2008, 09:05 AM - Replies (2)

[eluser]robertrick[/eluser]
Hi all. I am having trouble sending a single email message using the email class.
here's the issue.
I want to send one email with both HTML and Plain Text in the same email so that
if the person receiving the email can only view plain text they see the part that is
the plain text. and vice versa with the HTML.

and suggestions???


  How to retrieve database error from CodeIgniter
Posted by: El Forum - 04-11-2008, 08:09 AM - Replies (18)

[eluser]Erikk[/eluser]
Hello,

How do you actually retrieve database error when inserting data for example ?
db_debug would be turned off so you can handle errors your way - for example if you need so send back the error to an ajax request. What's the equivalent of say mysql_error() ?

Thankx.


  Extend Exceptions Class for DB Errors
Posted by: El Forum - 04-11-2008, 07:41 AM - Replies (1)

[eluser]Pascal Kriete[/eluser]
I've already extended the Exceptions class for php, general, and 404 errors. So I figured I could just add db errors as well.

I was wrong.
As it is right now the code looks like this:

Code:
function display_error($error = '', $swap = '', $native = FALSE)
{
//    $LANG = new CI_Lang();
    $LANG = new CI_Language();
    $LANG->load('db');

    $heading = 'Database Error';
    
    if ($native == TRUE)
    {
        $message = $error;
    }
    else
    {
        $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
    }

    if ( ! class_exists('CI_Exceptions'))
    {
//        include(BASEPATH.'core/Exceptions'.EXT);
        include(BASEPATH.'libraries/Exceptions'.EXT);
    }
    
    $error = new CI_Exceptions();
    echo $error->show_error('An Error Was Encountered', $message, 'error_db');
    exit;
}

What the?

The biggest issue here is that it creates a new Exceptions object. Why?
What's wrong with just calling the show_error method declared in common.php?

Also, why does it set $header if it's not used?

Should be something more like this:
Code:
function display_error($error = '', $swap = '', $native = FALSE)
{
    $LANG =& load_class('Language');
    $LANG->load('db');

    $heading = 'Database Error';
    
    if ($native == TRUE)
    {
        $message = $error;
    }
    else
    {
        $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error;
    }

    show_error($heading, $message, 'error_db');
}

EDIT: Ok, doesn't quite work like that because show_error only takes on argument. The point remains however.


  Ajax
Posted by: El Forum - 04-11-2008, 06:57 AM - Replies (1)

[eluser]Unknown[/eluser]
Hi.
I am new to web programming (read my intro)
But i know ill have to use Ajax technology to get the result i want but im really lost on that point.
Could anyone point me out on a really straight to the point walkthrough.
Im sure there is plenty on the net but i could'nt find one.
Basicly waht i need to be ablle to get accomplished is:

1- refresh an html table (or somekthing else if necessary) on a button click from information from a Mysql database.

2- Make a call to a php function to process some information in an html page to update the database.

i think that ajax could be a solution but i am not sure. (any other way to do it is great to)
but the main point is to avoid redirect and full page reloading.

But i am aware that i may be completly off track but i hope not.

More detaille for point 1:

I have an html table with time entry for employe. this page allow for modification and adding new entry.
I have the js_calendar plugin and when i select a datae on the calendar and click refresh i want to refresh the table for the time entry of that day.

If i get to do that i should be able to answer point 2 myself.


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

Username
  

Password
  





Latest Threads
Version number stays un-u...
by trunky
3 hours ago
codeigniter4/queue Not lo...
by mywebmanavgat
7 hours ago
Array to HTML "Table"
by HarmW94
8 hours ago
shortcodes for ci4
by xsPurX
10 hours ago
TypeError when trying to ...
by b126
Today, 12:04 AM
Webhooks and WebSockets
by InsiteFX
Yesterday, 10:39 AM
Retaining search variable...
by pchriley
Yesterday, 05:46 AM
Reading a session variabl...
by xanabobana
Yesterday, 05:05 AM
Update to v4.5.1, same us...
by kenjis
04-17-2024, 07:47 PM
Codeigniter 4 extend core...
by Semsion
04-17-2024, 05:08 AM

Forum Statistics
» Members: 84,593
» Latest member: margarethsmith
» Forum threads: 77,560
» Forum posts: 375,900

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB