This is my code:
public function client() {
echo "inside client controller";
function ordersData() {
echo "get clients orders data";
}
function create() {
echo "creating new client";
}
}
My call at the URL is
localhost:8080/app/controller/client
to show
"inside client controller"
or for example
localhost:8080/app/controller/client/create
to show
"creating new client"
.
Is it a good practice?
My Answer:
No, it is not considered a good practice to define functions within other functions in CodeIgniter or any other PHP framework. This can lead to code that is difficult to maintain, debug, and understand.
Instead, it is recommended to define all functions outside of the main function and then call them as needed within the main function. This will make your code more organized and easier to work with in the long run.
In your case, you should define the `ordersData()` and `create()` functions outside of the `client()` function and then call them within the `client()` function as needed.
Rate this post
5 of 5 based on 7997 votesComments