Creating a custom rule in Yii's URLManager to handle multiple parameters for controller actions

I'm looking to utilize the following URL:

index.php/form/2/fields/all

In order to display a list of fields with the same form ID. At present, I have a Form CRUD and a Fields CRUD.

FieldsController.php

public function actionAll()
{
  if (isset($_GET['form']))
  {
    $form_id = $_GET['form'];
    $model=$this->model()->findAllByAttributes(array('FORM_ID'=>$form_id), 'order'=> 'POSITION DESC');
    $this->render('all', array('model' => $model));
  }
  else
  {
    $this->render('error');
  }
}

What should the URLManager rule look like?

Answer №1

Include a defined parameter with the following criteria:

'form/<form:\d+>/fields/all' => 'fields/all'

You also have the option to exclude form

'<form:\d+>/fields/all' => 'fields/all'

This will generate the URL 10/fields/all

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am trying to figure out how to extract the filename from a form using PHP, but unfortunately, the $_FILES["filename"]["name"] method doesn't appear to be working. Can anyone help me with this issue

Having an issue with a form below that is supposed to extract some details into a mySQL database. Unfortunately, every time I try to retrieve the file in the form, it returns null. Unsure of the reason behind this, so any assistance would be much appreciat ...

The variable `$_SESSION` appears to remember solely the most recent value stored

Please check out the test page at . It seems like when I use $_SESSION to store the results of my database searches, only the last value gets stored in the session. The previous values seem to be getting emptied with each new search. I have used sessions ...

What is the most optimal structure for an if/else statement in PHP functions?

I have a question about the best way to handle returning conditions in a function, considering performance and coding practices. Should it be done like this: public function func_1() { if ( true == $condition) { // Do something return true; } ...

The successful execution of $.ajax does not occur

Starting out with ajax, I wanted to create a simple add operation. Here is the code that I came up with: HTML: <!doctype html> <html> <head> <title>Add two numbers</title> <meta content="text/html;charset=utf-8" h ...

Transfer information via ajax to yii controller

Thank you all for your assistance, it has been incredibly helpful. I am new to yii and feeling a bit overwhelmed at the moment. I have created a jQuery script to validate a form and then send it to my controller to process and save in the database. Howev ...

Utilizing the SELECT last_insert_id method for generating distinct and sequential identifiers

After exploring various options on different platforms, I have yet to find a solution that fits my specific scenario... SITUATION: I am working with a php system that automatically creates mysql-connected templates. For the system to function properly, e ...

Retrieve data from an Angular application embedded within a MVC C# application using a web crawler

UPDATE: I successfully resolved the issue by sending requests through cURL using AJAX URLs that Angular uses to communicate with .NET. To find these URLs, I used the Inspect tool in my browser. Here's what I did: curl_setopt($ch, CURLOPT_URL, "http ...

Sending PHP emails may encounter issues when there is a URL link enclosed in an anchor tag within the email body

There seems to be an issue with sending emails when including an "a href" tag in the mail body. The email sends successfully when the 'a href' and 'www' tags are removed, but this affects the display of other content as per my requirem ...

Different methods to send dynamically created vuejs array data to a mysql database

I'm currently utilizing this code in my LARAVEL project http://jsfiddle.net/teepluss/12wqxxL3/ The cart_items array is dynamically generated with items. I am seeking guidance on looping over the generated items and either posting them to the databa ...

Submitting form data in Angular is a straightforward process

I'm currently using the ng-flow library to upload images to my server. After a user drags and drops an image, I can successfully retrieve the HTML 5 file image in my controller. However, when trying to download it to the server along with other parame ...

Ways to transfer form data to an external website and showcase the information

In the process of developing a unique payment system, I have implemented a method where users complete a form and are then redirected to an external URL for checkout. After submission of the order details, I aim to pass them along to the external URL in o ...

Having trouble fetching the value with the designated ID

I'm encountering an issue with retrieving a value using an id. In my code, I have it set up like this: view <input type="text" value="<?php echo $add->class;?>" name="cls_<?php echo $add->id;?>" id="cls_<?php echo $add->id ...

Matching rules for UTF-8 character encoding in preg_match

Which preg_match rule should I use for the full_name field? I want user input to only include characters and not HTML or PHP code values, with a length between 3 to 11 characters. Here is an example of what I could use: <?php if (preg_match("%^[A-Z ...

Guide to inserting a space after the first character in a string

My variable $words contains the string "Unbelievable". I am trying to format it so that the output is U nbelievable. This is the code I have attempted: implode(" ", str_split($words, 2))." "; While this code works, it adds spaces after every 2 character ...

My WordPress loadmore function is not providing any additional posts

Hey everyone, I'm facing a Wordpress issue that I can't seem to resolve. I've checked other posts but haven't found the solution yet. So, I decided to share my code here and seek help. My problem is with trying to load more posts using ...

Could it be a mistake causing Echo to fail in fetching information from advanced custom fields?

When setting up in-content advertising for my blog posts on WordPress, I wanted the ads to point towards other sections of my site. Everything was working fine with the shortcode [in-content] pulling the most recent post from the 'advertising' cu ...

Challenges encountered when redirecting users with a combination of javascript and php

I have a login form that triggers a JavaScript function upon submission. This function calls a PHP page to process the input. The issue I'm facing is with how the redirections are displayed based on the user's role type. It attempts to display t ...

Transitioning to the Full Website with PHP Sessions - Discrepancies in Styling

I've encountered an issue when trying to switch from a mobile site to a full site using sessions. The styles on the full site do not load unless I refresh the page, at which point they finally appear. On my mobile page, there's a link that direct ...

How can I set up an additional "alert" for each form when making an AJAX request?

let retrieveLoginPasswords = function (retrieveForgottenPasswords, checkLoginStatus) { $(document).ready(function () { $('#login,#lostpasswordform,#register').submit(function (e) { e.preventDefault(); $.ajax({ type: &quo ...

How can I prevent an InnerText from being empty in an If statement with PHP?

I need assistance with skipping empty InnerText and assigning a default value in my code. Here is the code snippet: if (strip_tags($result[$c]->innertext) == '') { $c++; continue; } Below is the output: https://i.stack. ...