Comments (6)
this is what i do for multiple parameter
call_user_func_array(array($this->url_controller, $this->url_action), array($this->url_params));
// url_action no longer get parameter for easier multiple parameter
// now you can do like //site/controller/action/param1/value1/param2/value2 and so on
if (count($url) > 2 && count($url) % 2 == 0) {
unset($url[0], $url[1]);
$param = array_values($url);
for ($i=0; $i < count($param); $i++) {
if ($i % 2 == 0) {
$params[$param[$i]] = $param[$i+1];
}
}
$this->url_params = $params;
}
from mini3.
No you are wrong sir it is working perfectly just pass the url parameters to your controller method and then you can use them . you said that replacing call_user_func_array
with call_user_func
will solve the problem ?? have you tried that ? how would that be possible when we have to call an object method by parameters so we need the object the method and parameters like this call_user_func_array(array($this->url_controller, $this->url_action), $this->url_params);
while call_user_func
can only call a function with parameters (outside an object)
from mini3.
For me, when I changed it to call_user_func
, it worked.
In my specific situation, my controller is "Dashboard" and my method "org". If I call example.com/dashboard/org/param1/param2/ , and If I uncomment the debug lines in the splitUrl function, it returns:
Controller: dashboard Action: org Parameters: Array ( [0] => param1 [1] => param2 )
Therefore, url_params
is confirmed as an array as above. It's then passed to the controller and method/action as per line 44 in Application.
However, if my method is simply:
public function org($params){ echo gettype($params); }
it returns string.
If I change line 44 to call_user_func
but change nothing else (Ie: the arguments stay exactly the same), the above function returns an array.
HOWEVER, If I change line 44 to:
call_user_func_array(array($this->url_controller, $this->url_action), array($this->url_params));
This also works. It's like I have to declare url_params as an array type again for it to work. Somehow call_user_func_array almost converts url_params into a string because it's not explicitly stated as an array in the argument line (even though it's set as an array as per private $url_params = array();
So - PHP bug perhaps? Again, my skill is intermediate at best, so there might be something expected/normal that im missing here.
from mini3.
@hozzaq, Please where do i add this code?
from mini3.
from mini3.
So this is actually already done in the base code, it's just a bit wonky and undocumented.
When you go to http://example.com/controller/method/param1/param2/param3 you should hit the /controller/method/ page, with param1-3 passes as arguments (provided controller and method exist, but I'll get into that later). In order to call the parameters, you either have to declare them in the method, like:
public function index($param1 = null, $param2 = null, $param3 = null)
OR! Or you can leave the declarations out, and use func_get_args
like so:
public function index()
{
$params = func_get_args();
print_r($params);
}
Now, if you have a page, like /songs/ that you want to be able to do http://example.com/songs/1 or http://example.com/songs/1/edit etc, you can place the following code just after line 54:
elseif (is_numeric($this->url_action)) {
$this->url_params = array_merge([$this->url_action], $this->url_params);
$this->url_controller->index($this->url_params);
}
The only problem I've run into with this method is that your controller file can get a bit messy if you have a bunch of methods in that file.
This isn't really an issue with the way the site works (because you'd want /songs/bldfkjashfk to return a 404 error page), but more of what happens when a project doesn't have detailed documentation like the big projects tend to have. This can easily be remedied by writing a bit of a "how-to" on this, so it's not as confusing. Also, since this is just a framework, it's not meant to be the 100% solution to every problem you'll face, just a strong base to start your work from; some assembly will be required.
@panique You can probably close this issue, and open an ongoing task about creating documentation for the project to alleviate any future confusion.
from mini3.
Related Issues (20)
- Apache Rewrite Failure
- Fatal error: Uncaught Error: Class 'Mini\Core\Application' not found in HOT 2
- Fatal error: Uncaught Error: Class 'Mini\Model\PDO' not found in HOT 4
- German umlauts (ä, ö, ü, and possibly other special characters) removed in parameters of action functions HOT 2
- Import Bootstrap CSS/JS from node modules using NPM HOT 1
- Generating PDFs with PHP mini HOT 3
- can't save the data coming from the database HOT 1
- can't deploy on heroku ! HOT 1
- PDO Debug d'ont work HOT 1
- new folder into of controller is possible? HOT 4
- I've this issue HOT 3
- Bug
- Post request as API is not working
- I Cant Upload Files To Public File
- undefine lastInsertId() HOT 1
- Post a form in Ajax HOT 6
- Fork work with postgresql HOT 3
- How to share function across all views HOT 4
- Pull 61 wasn't applied to the develop branch. HOT 2
- Cleanup some issues HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mini3.