CodeIgniter Forums
Comprehensive CodeIgniter completions for Sublime Text 2 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Comprehensive CodeIgniter completions for Sublime Text 2 (/showthread.php?tid=50083)

Pages: 1 2


Comprehensive CodeIgniter completions for Sublime Text 2 - El Forum - 03-13-2012

[eluser]martin_redola[/eluser]
I got a little sick of typing functions like
Code:
$this->load->view('header', $data)
and
Code:
$this->db->insert('mytable', $data)
and couldn't find a comprehensive completions file for my favourite text editor, so I gathered together every single CodeIgniter function from the User Guide and put them into a sublime-completions file.

You can grab it from the Github repo here: https://github.com/martinredola/sublimetext2-codeigniter-completions. Then just pop it in your /Packages/PHP folder.

Remember that Sublime Text is smart, so just typing thdbins will be enough to bring up
Code:
$this->db->insert('mytable', $data)
If you just type this, you can scroll through the lot of them.

It has saved me so much trouble that I thought I'd share.


Comprehensive CodeIgniter completions for Sublime Text 2 - El Forum - 03-13-2012

[eluser]kreamik[/eluser]
hi how to use this completion?
i have add it to my :
C:\Users\Kreamik\AppData\Roaming\Sublime Text 2\Packages\PHP

and nothing happen ..
what i miss?


Comprehensive CodeIgniter completions for Sublime Text 2 - El Forum - 03-14-2012

[eluser]martin_redola[/eluser]
In Sublime Text 2 go to Preferences > Browse Packages and then double click the PHP folder. Put the sublime-completions file in there and restart the program.

Auto complete must be set to true for the completions to appear as you type, otherwise press Ctrl+Space.


Comprehensive CodeIgniter completions for Sublime Text 2 - El Forum - 03-14-2012

[eluser]CroNiX[/eluser]
I don't use sublime2, but doesn't sublime do code completion on its own? Many apps have a hard time reading CI's singleton, so it's a common problem. If it does, perhaps this might be easier to do. I know it works for Zend Studio and a few others...

You basically create a library in the library folder that looks like:
Code:
class CI_Controller {
    /**
     * @var CI_DB_active_record
     */
    public $db;
    
    /**
     * @var CI_Loader
     */
    public $load;
    
    /**
     * @var CI_Output
     */
    public $output;    

    //etc...All other CI classes/libraries/etc.
    //put your custom controllers, libraries, etc., as well and they will show up too.
}
Which allows the app to map things how they should be. All methods show up automatically, so this would be a lot easier to maintain through versions (if it works for you). You don't have to load the library (would probably cause problems). It just needs to be present so the app can read it.


Comprehensive CodeIgniter completions for Sublime Text 2 - El Forum - 03-14-2012

[eluser]martin_redola[/eluser]
That looks like a good way of doing things if I were using a heavier IDE, but Sublime Text 2 is a text editor so it doesn't scan your projects in that way (or if it does, I've missed something big style). There are plug-ins which can do that, but I've found they don't work properly, and I use Sublime Text because it is lightweight and I don't need that extra functionality - I first and foremost need speed.

So for me it was easier to write a script to scrape the CI User guide and then pile the functions into a single file and slot it into the PHP folder.


Comprehensive CodeIgniter completions for Sublime Text 2 - El Forum - 03-21-2012

[eluser]kreamik[/eluser]
if i want to write $this->input->post
nothing happen after i typed $this->input
i have to press ctrl+space then scroll and take more time to find out the syntax



Comprehensive CodeIgniter completions for Sublime Text 2 - El Forum - 04-05-2012

[eluser]zbrox[/eluser]
Kudos for your efforts!


Comprehensive CodeIgniter completions for Sublime Text 2 - El Forum - 05-22-2012

[eluser]SPeed_FANat1c[/eluser]
I put that file in PHP directory, restarted the program but nothing changed. Have you ideas what could be the problem?


Comprehensive CodeIgniter completions for Sublime Text 2 - El Forum - 05-30-2012

[eluser]onuryasar[/eluser]
thanks, that works like a charm!


Comprehensive CodeIgniter completions for Sublime Text 2 - El Forum - 06-29-2012

[eluser]Unknown[/eluser]
Thanks, Martin, this is great.

For anyone having trouble: By default Sublime Text only triggers on characters, so if you're trying to auto-complete by typing "$this" it isn't going to work. Instead, try typing "this" and you should see the list pop up.

You can add
Code:
$
as a trigger in your preferences:

Code:
"auto_complete_triggers": [ {"selector": "text.html", "characters": "<$"} ],

The
Code:
<
is there by default for HTML purposes, and the
Code:
$
was added for PHP.

While you're in there, might as well change it to tab completion rather than enter!