Welcome Guest, Not a member yet? Register   Sign In
  image upload ,form validation, and image resize
Posted by: El Forum - 09-07-2007, 04:25 AM - No Replies

[eluser]matt2012[/eluser]
Having spent a bit of time on this and seeing others here doing the same thought id post my controller here, which will:

1) validate form
2) validate upload
3) upload image
4) create thumbnail *edit changed to GD2 for better quality thumbnails
5) insert data into table

you will need to load validation and form library somewhere first.

There's my stuff in there which can be ignored (i.e. basic page set up).

Code:
function edit_service_6()
    {        
        //basic page setup
        $data = template($this->data['options']);    
        $pid = $this->input->post('id_dir1');
        $id = $this->uri->segment(3,$pid);        
        $data['id'] = $id;
        $data['content'] = 'admin/edit_service_6';
        //upload set up
        $data['error'] = '';
        $data['upload_data'] = '';
        //check if folder exists
        if (!is_dir("./services/".$data['name'])){
        //if not create it with correct permissions
        mkdir ("./services/".$data['name'], 0777); }
        $config['upload_path'] = './services/'.$data['name'];
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '500';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        //form set up
        $rules['title']    = "required|min_length[5]";    
        $fields['title']  = 'title';    
        $this->validation->set_rules($rules);
        $this->validation->set_fields($fields);    
        //thumbnail set up
        $config2['image_library'] = 'GD2';      
        $config2['create_thumb'] = TRUE;
        $config2['maintain_ratio'] = TRUE;
        $config2['width'] = 300;
        $config2['height'] = 200;
        
        // check whether form has been run and validates
        if ($this->validation->run() == FALSE)
        {
        //if no do nothing
        }
        //else yes so do upload
        else
        {
        $this->load->library('upload', $config);
            //if upload not success display errors
            if ( ! $this->upload->do_upload())
            {
                $data['error'] = $this->upload->display_errors();        
            }
            //else do form insert, image upload and image resize!!
            else
            {        
            //upload data
            $data['upload_data'] = $this->upload->data();
            //resize image
            //needed this from upload data
            $config2['source_image'] = $data['upload_data']['full_path'];
            $this->load->library('image_lib', $config2);
            $this->image_lib->resize();        
            //form insert
            $type = str_replace('image/','.',$data['upload_data']['file_type']);
            $this->Servicemodel->insert_photo($data['upload_data']['raw_name'], $data['upload_data']['file_name'], $type);                
            }    
        }    
        $data['images'] = $this->Servicemodel->get_service_photos($id);
        $this->load->view('MyViews/container2', $data);
    }


  Using a Three-tier architecture with Code Igniter
Posted by: El Forum - 09-07-2007, 04:15 AM - No Replies

[eluser]Druidor[/eluser]
Hello,

I'd like to use Code Igniter in my company, but the do want a three-tier architecture (data, business, presentation) with 3 differents servers for security reasons. I know this is a Java-style architecture but do you think I could use code Igniter in a 3-tier architecture ? If so, how ?

Thanks in advance.


  accessing database in a static function
Posted by: El Forum - 09-07-2007, 04:13 AM - No Replies

[eluser]yuccaplant[/eluser]
Hi,

I'm new to CI and kind of new to php. In a model, I want to a static funtion to get all my entries from the database. However I can't reference $this in a static function. Are there other ways to reference db->get('')?

Something like this:

Code:
public static function get_all()
    {
        $query = this->db->get('entries');
        $entries;
        foreach ($query->result() as $row)
        {
            $entries[] = new Entry($row->id,$row->title, $row->body);
        }
        return $entries;
    }


  rewrite and comma problem
Posted by: El Forum - 09-07-2007, 01:32 AM - No Replies

[eluser]wojtekk[/eluser]
hi
Im making new version of old page and need redirect(301) old links to new links but old got 'commas' and i get error
The URI you submitted has disallowed characters.
so i change in config

Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_-,';
and now i get error
Code:
A PHP Error was encountered

Severity: Warning

Message: preg_match() [function.preg-match]: Compilation failed: range out of order in character class at offset 17

Filename: libraries/Router.php

Line Number: 408
The URI you submitted has disallowed characters.


any help?
thx


  Modules and partials
Posted by: El Forum - 09-06-2007, 10:40 PM - No Replies

[eluser]dfau[/eluser]
I would like to be able to show a partial view of a module. Example: a module whose job is to manage a calendar - allow the user to assign appointments to dates, tick them off and so on. It would be good to have a mini-view of the calendar on the sidebar, but managed and controlled by the calendar controller. I'm thinking of each controller having callback functions and each module having hooks (not CI hooks).

I've read through dynazack -> zawk -> zacharias' modular separation thread (http://ellislab.com/forums/viewthread/46669/), and also the mini-controller idea floated by Rick Jolly (http://ellislab.com/forums/viewthread/58405/) and would guess I'm after a blend of the two. The issue is that it would be good to retain the modular separation (application/modules/<...>) without adding an extra library into application (application/libraries/<...>).

So:
1) Is it possible to have application/modules/<module>/libraries as is?
2) If not, is it possible to setup application/modules/<module>/libraries in zacharias' modular separation code?
3) If not, is it possible to call a controller from another controller?
4) If not, would extending the base controller be of any use?
5) Am I making any sense at all?

Many thanks,
df


  Resize image on the fly
Posted by: El Forum - 09-06-2007, 08:57 PM - No Replies

[eluser]K-C[/eluser]
How can I display a resized image on the fly. E.g. I uploaded an image size 200 X 200.
How can I display it at any time with different size e.g. 150 X 150, 100 X 100?


  Table data presentation in template/view
Posted by: El Forum - 09-06-2007, 04:19 PM - No Replies

[eluser]Monotoba[/eluser]
Hello,

I'm brand new to code igniter and I am wondering if someone here can provide a demo of using nested loops for data presentation using the template system in ci. Here's a template to show you what I mean. How would I get the template engine to display data in a multidementional array containing multiple color rows containing multiple color cells?

Thanks for the help


&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Color Table Demo</table>
&lt;/head&gt;

&lt;body&gt;

<table>

{color_row}
<tr>

{color_cell}
<td width="15" bgcolor="#{color}"> <font color="#{font_color}> {color} </font> </td>
{/color_cell}

</tr>
{/color_row}

</table>

&lt;/body&gt;

&lt;/html&gt;


  query called in function error
Posted by: El Forum - 09-06-2007, 03:04 PM - No Replies

[eluser]sixpack434[/eluser]
ok please help, my head is about to explode. Outside codeigniter this works but for some reason it doesn't inside the codeigniter framework. i'm in the process of transfering my site to using codeigniters framework. anyway the problem:

In my index page I am trying to show for lesson boxes by called a function called showLesson($lessonNo);

e.g.
$query = $this->db->query("SELECT lessonNo FROM lesson ORDER BY dateTime DESC LIMIT 4");
foreach($query->result_array() as $row){

showLesson(10);
}


In showLesson I have a query to get lesson details and display them e.g.
$lessonDetails = mysql_fetch_assoc(mysql_query("SELECT * FROM lesson WHERE lessonNo='$lessonNo'"));
$name = $lessonDetails["name"];
$difficulty = $lessonDetails["difficulty"];
$details = $lessonDetails["details"];

For some reason only the first lesson is shown on the index page and not the other 3. I get the following error

Message: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource

referring to $lessonDetails above in showLesson. Now this works outside codeigniter no problem, why is codeigniter being difficult!!

thanks


  Example with taking user back to referring URL after login prompt
Posted by: El Forum - 09-06-2007, 11:44 AM - No Replies

[eluser]stevefink[/eluser]
Hope I'm elaborating on what I'm trying to do properly. :-)

I'm looking for an elegant way for say when a user accesses:

http://foo/login/bar , this requires a validated $_SESSION, so it redirects them back to,

http://foo/login ..

After a successful login, should I just check for something like $_POST['referrer_url'] and refer them back to there afterwards? I'd like the user to be able to get back to http://foo/login/bar instead of say http://foo/login/success_login_landing_page

Hope that makes sense. :-)

Cheers!

- sf


  Any support link for Ajax for CI
Posted by: El Forum - 09-06-2007, 11:10 AM - No Replies

[eluser]millisami[/eluser]
Hi,
Is there any support forum for Ajax for Code Igniter?
Thanks


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

Username
  

Password
  





Latest Threads
Any user guid or video o...
by msnisha
3 hours ago
MVC vs MVCS vs CodeIgnite...
by massimiliano1.mancini
7 hours ago
Why PHP is still worth le...
by php_rocs
Today, 05:13 AM
Is hiring a digital marke...
by Markhenry123
Today, 02:45 AM
my controller fails to fi...
by PaulC
Today, 01:40 AM
My Library cannot see ses...
by InsiteFX
Yesterday, 08:48 PM
update the framework to t...
by captain-sensible
Yesterday, 12:14 PM
CodeIgniter Shield 1.0.0 ...
by Ayatorvi
Yesterday, 06:06 AM
Update to 4.6.1
by serialkiller
05-07-2025, 11:58 AM
Can't create new database...
by paulbalandan
05-07-2025, 08:49 AM

Forum Statistics
» Members: 144,977
» Latest member: gnexterior
» Forum threads: 78,382
» Forum posts: 379,420

Full Statistics

Search Forums

(Advanced Search)


Theme © iAndrew 2016 - Forum software by © MyBB