Welcome Guest, Not a member yet? Register   Sign In
Code competion in views
#1

[eluser]kobbe0[/eluser]
Hey, have been looking for this like crazy with new luck.

Is there a way to get code completion to work in views?

Example.

In my controller I load a model:
$this->load->model('test_model');

In my view file I use:
$this->test_model->test_function();

I tried use stuff like this in my view file but can't get it to work.
/**
* @var $this Test_model
*/
/**
* @var $this Test_controller
*/


Are there any way to get this to work using phpDoc?

For controllers and models it works perfect using:
https://github.com/topdown/phpStorm-CC-Helpers

Also I use phpStorm but I guess with correct phpdoc it should work in all IDEs?

Thanks!
#2

[eluser]InsiteFX[/eluser]
PHP code will not show up in a view file when ran!
#3

[eluser]kobbe0[/eluser]
I don't undestand you at all, but I'm pretty sure you totaly miss understood my question.

For IDE auto completion to work file must be properly documented with phpdocs. I wonder how do do this in a view file. A view file is called from a controller. In the view file it's possible to use $this->test_model->test_function(). But since the view file is a seperate file it doesn't understand where $this, test_model or test_function come from. I know view files should have as little php code as possible but in this case I'm taking over form coders that have used to call models directly from the view file.
#4

[eluser]InsiteFX[/eluser]
Same way you would for any other php file, view files are php files
Code:
<?php
/**
*
*/
?>
#5

[eluser]kobbe0[/eluser]
Wow, am I that hard to understand? English is not my native language but I re-read my question and I still understand.
#6

[eluser]InsiteFX[/eluser]
Code Completetion is up to your php editor and has nothing to do with views!

Maybe you should define your problem better!
#7

[eluser]kobbe0[/eluser]
Yes I know that. But for code completion to work the files need to be documented the correct way. So this should be basicly the same for all IDE.
The point is the view file is basicly a blank php file that is "included" via $this->load->view('test_view').

If you use something like $this->test_model->test_function() from the view file no IDE can know where $this variabel come from. That is why I ask how to document it.

Reason why I ask here is because having view file like this is a codeigniter thing (even if other framework may have it) so people here maybe had the same problem and found a fix.

I have been trying to define my problem as good as possible...
#8

[eluser]boltsabre[/eluser]
Quote:no IDE can know where $this variabel come from. That is why I ask how to document it.
I think you just answered your own question, if "no IDE can know where $this variabel come from", you cannot document it.

It sounds like you're between a rock and a hard place... for starters, that kind of code logic should never be inside a view, it just goes against the entire principle of a MVC framework (yes, I know you didn't code it like that, someone else did).

So, you choice now, it seems is to be either to manually code in your documentation comments into your view, or remove offending code back into its appropriate controller/model.
#9

[eluser]kobbe0[/eluser]
Well, it's there the magic of using PHPDoc comes in use, and what my question is about.
http://en.wikipedia.org/wiki/PHPDoc#Tags

I know this is not a codeigniter question, more of a MVC question.

For example if you use a varible from the controller in the view you can do like this:
/*
* @var $test array
*/
That way the framework atleast knows that $test is an array.

In a controller you can use something like this:
@property Cart_model $cart_model
And you will get full model-support in the controller when you use $this->cart_model->whatever().

So my question stands. But I guess I have to look else where.




Theme © iAndrew 2016 - Forum software by © MyBB